Sunday, May 17, 2009

Making Multiline Equations

Just a quick post, as this is something that I've had to do (yet again), so I thought I'd write it down. When you need an equation with multiple lines, say when you're decomposing an equation through several steps, the procedure you should use is eqnarray:

Equation array: eqnarray
usage: \begin{eqnarray} ... \end{eqnarray}

The usage of eqnarray is fairly straight-forward: an equation array is a standard array with three columns formatted to the right, center and to the left {rcl}. The idea is that the left side of the equation is the first statement, the middle column is the = sign and the right column is the derivation. It differs from a standard array in that it is in the formula environment (within the $ environment) so it can take standard mathematical notation. The following example produces a two-line equation:

\begin{eqnarray*}
\Delta D(s,N) & = & D_N(\hat{\mu};,y) - D_{N_L,N_R}(\hat{\mu}_L,\hat{\mu}_R;y)\\
& = & \sum_{i=1}^n D(\hat{\mu};y_i) - \left[\sum_{i=1}^{n_L} D(\hat{\mu};y_i)+\sum_{i=1}^{n_R} D(\hat{\mu};y_i)\right]\\
\end{eqnarray*}

This produces the following equation:

2 comments:

  1. I've also been using eqnarray, but apparently it is now obsolete. You should use the align environment instead, it has more consistent spacings.

    http://texblog.net/latex-archive/maths/eqnarray-align-environment/

    ReplyDelete
  2. Yeah, I've read that as well, and I use align now too, but I like eqnarray still when the middle column, the = in this case, is more complex.

    ReplyDelete