245

Motivation

I want to include a list of related equations, say, for a proof, in my LaTeX document. As far as I know, I have two good options, eqnarray and align.

Question

What is the difference between eqnarray and align, and how do I know which I should be using? Or does it matter at all?

5 Answers 5

222

Although eqnarray may seem to work "well enough", Avoid eqnarray! Avoid eqnarray! Avoid eqnarray!

Two main problems are mentioned in the doc above:

  • eqnarray sets horizontal space around the = operator that is not consistent with the space set in other environments, such as \[...\] or $$...$$ (it is wider).
  • eqnarray (also eqnarray* !) has an ill-defined equation numbering, which leads to numbering errors on referencing—mostly when using the command \nonumber

Use align and the rest of the ams environments. See texdoc amsldoc (PDF) or the Short Math Guide for LaTeX for documentation on how to use them.

14
  • 10
    "avoid eqnarray" has been updated and published in tugboat 33:1. this will be accessible only to tug members until spring 2013, but after that it will be open to anyone. Dec 15, 2012 at 17:50
  • 7
    @masu: eqnarray was written before the other (better) environments were written. Now that the better ones exist, there is no longer any reason to use eqnarray (unless for some reason you can't use the amsmath ones). Oct 30, 2013 at 4:03
  • 13
    Your answer lacks justification... please elaborate.
    – Paul
    Nov 27, 2014 at 16:35
  • 7
    @Paul: I think the three linked justifications are more than enough. (Especially the first one: the entire article by Lars Madsen titled "Avoid eqnarray!".) Yes it would have been better to include some of them in the answer in case the links rot, but on the other hand it's hard to replicate those visual elements from a PDF to this HTML page (would have to take screenshots or something). Nov 28, 2014 at 1:23
  • 3
    One more point, now that I am reading "Avoid eqnarray!": You don't have to reproduce the entire document here. Even a simple summary like "eqnarray produces spacing that is inconsistent in these three ways" would be helpful. Some of the other answers make reference to spacing problems, but no answers here clearly summarize the spacing problems.
    – Mars
    Mar 3, 2018 at 17:18
70

align is from amsmath, while eqnarray is from base LaTeX, so I would expect the former to be better. Some differences:

  • eqnarray has two alignment points (it's basically just array with a default preamble); align has one. x + y &=& z versus x + y &= z
  • eqnarray changes the spacing at the alignment points depending on different factors; align keeps it fixed (which is generally what you want)
  • eqnarray allows page breaks between lines; align doesn't
  • \\ * is treated the same as \\* in eqnarray, but won't work in align (since * shows up commonly in equations)

(largely from The LaTeX Companion §8.2.1)

2
  • 18
    i consider the first point to be an advantage of eqnarray. how can i simulate this behavior with align? i need it whenever i have operators of different width, e.g. = vs ==. i want = to be centered below ==, not left aligned to it.
    – peter
    Jul 24, 2013 at 12:19
  • 7
    align allows page breaks between lines with the global declaration \allowdisplaybreaks.
    – skpblack
    Oct 3, 2014 at 0:11
35

Besides the better spacing and the fewer ampersands to type, a big advantage of align vs eqnarray is that you can include a \qedhere at the end of the last line and have the nice CQFD square (also called a “Halmos”) placed at the same height as your last formula, and not underneath.

\begin{proof} The proof is a follows: 
\begin{align}
(x+y)^3&=(x+y)(x+y)^2\\
       &=(x+y)(x^2+2xy+y^2)\\
       &=x^3+3x^2y+3xy^3+x^3.\qedhere
\end{align}
\end{proof}

enter image description here

20

The align environment only works if you use the AMS (American Mathematical Society) packages. If you need to use journal specific document classes or style files, the align environment may not be available. (For example, when I needed to use the iopart class for submission to an Institute of Physics journal, I had to change all my aligns to eqnarrays for the file to compile.

But unless you are forced to, I generally recommend the align environment. Here's a good write-up of what the differences are.

13

If you must use the eqnarray environment, there's a package called eqnarray (available here) that at least removes the excessive space around the middle column. Compare:

\documentclass{article}

\usepackage{eqnarray,amsmath}

\begin{document}

\begin{eqnarray*}
A&=&B,\\
C&=&D,\\
E&=&F
\end{eqnarray*}

\begin{align*}
A&=B,\\
C&=D,\\
E&=F
\end{align*}

\end{document}

The package is for LaTeX 2.09, but it might still work.

I notice that, in my example, the eqnarray* and align* are centered very slightly differently (the eqnarray* is less than 1 point to the left of the align*). I'm not sure why. If you use {B,} and {D,} instead of B, and D, in the eqnarray*, the two displays come out centered exactly the same, so I assume that the ending punctuation symbols are causing the problem. (The default eqnarray* appears to have the same issue.)

1
  • 1
    Does the package {eqnarray} works with Cleveref? That is one of the biggest drawbacks of {eqnarray} ....
    – Paulo Ney
    Apr 21, 2018 at 16:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .