214

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?

189

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.

| improve this answer | |
  • 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. – barbara beeton Dec 15 '12 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). – ShreevatsaR Oct 30 '13 at 4:03
  • 13
    Your answer lacks justification... please elaborate. – Paul Nov 27 '14 at 16:35
  • 6
    @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). – ShreevatsaR Nov 28 '14 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 '18 at 17:18
64

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)

| improve this answer | |
  • 15
    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 '13 at 12:19
  • 7
    align allows page breaks between lines with the global declaration \allowdisplaybreaks. – skpblack Oct 3 '14 at 0:11
32

Besides the better spacing and the less 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

| improve this answer | |
18

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.

| improve this answer | |
11

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.)

| improve this answer | |
  • 1
    Does the package {eqnarray} works with Cleveref? That is one of the biggest drawbacks of {eqnarray} .... – Paulo Ney Apr 21 '18 at 16:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.