TeXblog

 Typography with TeX and LaTeX

eqnarray vs. align

12 April 2008 by Stefan Kottwitz

There’s a lot of freely available documentation for LaTeX, but there’s a pitfall: some documents that are still online are outdated and therefore contain obsolete information. Documents like “Obsolete packages and commands” (”l2tabu”) address the need of up-to-date information.

For instance the obsolete eqnarray environment frequently appears in questions of new LaTeX users and many people including me usually answer: don’t use eqnarray and give advice how to use the align environment of amsmath instead.

Here’s a summary of the problems with eqnarray:

  • the spacing around relation symbols are inconsistent,
  • long equations might collide with the equation numbers,
  • there could be problems with labels and references.

Here is one small example document just to illustrate the space inconsistany problem:

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\begin{document}
\begin{minipage}{0.5\textwidth}
equation:
\begin{equation*}
  z_0 = d = 0
\end{equation*}
\begin{equation*}
  z_{n+1} = z_n^2+c
\end{equation*}
align:
\begin{align*}
  z_0 &= d = 0 \\
  z_{n+1} &= z_n^2+c
\end{align*}
eqnarray:
\begin{eqnarray*}
  z_0 &=& d = 0 \\
  z_{n+1} &=& z_n^2+c
\end{eqnarray*}
\end{minipage}
\end{document}

Compile for yourself and examine it, if you want. For a quick look here’s a screenshot of the output:

eqnarray vs. align

Notice the difference of the spacing around the equal sign in the eqnarray environment compared to equation and even compared to the other equal sign inside the first eqnarray line.
If you try to repair the spacing by adjusting \arraycolsep you will notice that all other arrays including matrices will be affected too. So the best solution is to use amsmath, this package provides even more environments useful for multiline formulas and a lot more enhancement for mathematical typesetting.

See the amsmath user’s guide.

For further information regarding this topic you may have a look at the article “Avoid eqnarray!” by Lars Madsen published in the PracTeX Journal 4 2006.

This topic was discussed on MatheBoard.

This entry was posted on 12 April 2008 at 10:08 PM and is filed under Mathematics. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

7 responses about “eqnarray vs. align”

  1. Catherine Davey said:

    Very useful! I have been wondering what the difference is. Thanks!

  2. Brad said:

    Where is the documentation and specifications for the align environment ? For example, how do you control if it aligns a certain column left or right ?

  3. Stefan Kottwitz said:

    Hi Brad,

    the align environment has an implicit {rlrl…} alignment of its columns. The environment is documented in the amsmath user’s guide, further information can be found in the general Mathmode document.

    Stefan

  4. Bob said:

    One problem with the align environment is it appears that the \pause command in Beamer does not work in align as it does in eqnarray. This may seem minor, but it’s important in my lectures to be able to step through multiline equations. Align does seem to be much nicer otherwise, so I would appreciate if anyone has advice on the pauses. Thanks!

  5. David Schaich said:

    Bob,

    Beamer’s \pause doesn’t actually work inside any amsmath environment, “since these do really wicked things” according to the Beamer manual (v.3.06, page 63). You can find some workarounds through Google, though just using eqnarray in this case is the simplest.

  6. Stefan Kottwitz said:

    You could step through align environments using the \uncover macro. It works for unnumbered (starred) and numbered align environments, in the last case an empty untagged last line is necessary, see the beamer user guide 23.4 Uncovering Tagged Formulas Piecewise.

  7. Bob said:

    Thanks for the responses. The \uncover solution works well. I wish I would have checked back here sooner. I’ll be using that a lot from now on. Thanks.

Leave a Reply