eqnarray vs. align

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.

12. April 2008 by stefan
Categories: Mathematics | 92 comments

Comments (92)

Leave a Reply to alem