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:

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.




2 April 2009 at 3:04 AM
Very useful! I have been wondering what the difference is. Thanks!
22 August 2009 at 4:59 PM
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 ?
22 August 2009 at 10:42 PM
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 September 2009 at 11:40 PM
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!
2 October 2009 at 10:25 PM
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.
3 October 2009 at 1:12 AM
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.
24 January 2010 at 8:40 PM
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.
17 March 2010 at 5:46 PM
Hi, i’ve got a Problem with \align.
According to your article I started to change the \eqnarray s in my documents into \align s. But in a certain case, don’t know why, I get a strange space, here is an example:
”
\documentclass{scrreprt}
\usepackage{amsmath}
\begin{document}
\begin{eqnarray}
a & = & b\\
b & = & c
\end{eqnarray}
\begin{align}
a & = & b\\
b & = & c
\end{align}
\end{document}
”
I’d be happy if you could explain to me, where these huge space in the align between = and b comes from and how I can avoid it. Thanks.
17 March 2010 at 9:59 PM
Hi Christian!
In align environments the & symbol doesn’t separate columns, it marks the relation symbol. The correct way would be:
The second & would cause an additional align-column, that’s why there’s that space. To see it try:
Stefan
5 April 2010 at 6:42 AM
I’ve got a different problem with align. I would like to label an equation with tag{H_T}, but the subscript gets it really confused and unhappy. tag{{H_T}} doesn’t fix it. Any ideas?
6 April 2010 at 9:47 PM
Hi Allen,
use math mode in the argument of tag, \tag{\(H_T\)} or \tag{$H_T$}.
Stefan
6 April 2010 at 10:27 PM
Excellent, thank you!
11 April 2010 at 1:53 PM
Thanks for your answer, now I understand how align works, think I’m gonna use it every time now.
Christian
14 April 2010 at 4:24 PM
Hi all,
I have a couple more questions on align:
Is it possible to adjust the multi-column behavior in align? I’m looking for something like array, but that could display math in equation-style (big vees etc.)
Also, can I add/eat the space between the lines? I want to have dots leading to the last equation, but the line containing \vdots is unevenly spaced with the ones around it:
\begin{align*}A_1 &= B_1\\
&\ \ \vdots\\
A_n &= B_n
\end{align*}
Thanks a lot,
Andrew
15 April 2010 at 4:22 PM
Hi Andrew,
concerning multiple columns, amsmath provides several align-like environments, have a look at amsldoc.pdf. I’m often using the alignat environment when several columns are needed.
Line specific spacing is possible, just state the space in square brackets after the linebreak, for instance:
Negative space is possible as well:
A_1 &= B_1\\[-5pt]Stefan
18 April 2010 at 3:15 PM
Thank you Stefan!
28 May 2010 at 8:20 AM
I have a problem with align. I’d like to label each row with \label{} so that I can refer to the equations individually. I get an error message that multiple labels are not possible.
\begin{align}
a &=b\label{eq1}\\
c &=d\label{eq2}
\end{align}
28 May 2010 at 7:31 PM
Hi Anna,
there’s no problem in this code. This complete example is compilable without error and refers to both equations:
Try this one. Perhaps post a complete example here, like I did, that shows the error. Something else causes this problem, not visible in the piece of code here.
Stefan
9 June 2010 at 8:26 AM
Hi all,
I just have few questions on fancy headings should some one extends a helping hand. I am writing a thesis and want to use this fancy thing. Here is what i have so far:
\documentclass[reqno,12pt, twoside ]{article}
\usepackage{fancyheadings}
\renewcommand{\sectionmark}[1]{\markright{\thesection \ #1}{}}
\renewcommand{\subsectionmark}[1]{\markright{\thesubsection \ #1}{}}
\rhead{\leftmark\\\rightmark}
\fancyhead[LE,RO]{\slshape \rightmark}
\fancyhead[LO,RE]{\slshape \leftmark}
\fancyfoot[LE,RO]{\thepage}
My questions:1. I want to remove the heading for the main titles(sections) while keeping the page number as it used to be(left or right depending on…)
2. I want to have the section title on the left hand side of the (even numbered pages) and the subsection title on the right hand side of (odd pages).
Any help would be appreciated.
9 June 2010 at 9:30 PM
Hi Alem,
I recommend to use fancyhdr instead of fancyheadings, this is an early version. Since you are writing a thesis consider to use another class than article. The article class is appropriate for smaller documents. You could use report or book instead, there are even some dedicated thesis classes.
book and report provide chapters. chapter starting pages would have another style, numbered but without heading. That may be what you would like to achieve.
Have a look at the fancyhdr documentation for explanation and examples. If you still have questions just write them here.
Stefan
10 June 2010 at 9:11 AM
Thank you Stefan. I have been advised not use this chapter thing. If i do, i have to make sure that the word chapter should not appear where the chapter is supposed to begin. I can suppress it using \chapter*{title}. The problem is then i need to have the chapter number before the title.
Yes you right, with this book or report document classes, the header from the chapter or mains section will disappear which is what i want. The problem with this is again, it puts the page number for that page at the center. I want the page number to be on the right.
11 June 2010 at 11:34 PM
Hi Alem,
using a KOMA class could help. They are much more customizable. Further they don’t write out “Chapter” and they provide a very good package for headings and footers. The position of the page number looks also like you wished.
Test this small example:
The documentation will explain more, there’s a whole chapter dedicated to headings.
Stefan
18 June 2010 at 10:42 AM
Thanks Stefan. This was what i had been looking for.It solved my problem!!!
30 June 2010 at 6:37 AM
I’ve been using align for years, however, the environment doesn’t seem to be a part of {iopart, iopams} (for publication in AMS journals), while eqnarray works - so there actually are situations where you can’t avoid using it. …and yes, the spacing is ugly!
24 July 2010 at 9:05 AM
how to move the equation to left-hand side or right-hand side?
24 July 2010 at 11:03 AM
To place the equations on the left side for the whole document, use the option fleqn for the document class or for the amsmath package.
Alternatively, to align equation arrays to the left or to the right side, you could use the flalign environment. Just use an additional column separator & on the right respectively the left side.
31 July 2010 at 9:34 PM
Thanks, you saved my day
24 August 2010 at 4:58 AM
Hello Mr. Stefan!
I would like to thank for the excelent post! I was using eqnarray a lot… However, it seems that there is a comment with a problem wich i have for my own, and is not answered… It seems that the problem is with the package “ntheorem”
The problem is with align’s labels.
\documentclass[a4paper,11pt,twoside]{article}
\usepackage[utf8]{inputenc}
\usepackage[portuguese]{babel}
\usepackage[pdftex]{graphicx}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage[thmmarks]{ntheorem}
\begin{document}
\begin{equation}\label{e1}
equation1
\end{equation}
\begin{align}
equation2 \label{e2}\\
equation3 \label{e3}
\end{align}
\begin{align}
equation4 \label{e4}\\
equation5 \label{e5}
\end{align}
\begin{equation}\label{e6}
equation6
\end{equation}
Equations \ref{e1}, \ref{e2}, \ref{e3}, \ref{e4}, \ref{e5}, \ref{e6}
Equations \eqref{e1}, \eqref{e2}, \eqref{e3}, \eqref{e4}, \eqref{e5}, \eqref{e6}.
Then there are errors with labels
! Package amsmath Error: Multiple \label’s: label ‘e1′ will be lost.
However, if i put
\begin{equation}\label{e1}
equation1
\end{equation}
\begin{align}
equation2 \\
equation3
\end{align}
Then ref{e1} gets reference to equation 2!
It seems that if I remove ntheorem from the file, it compiles ok. Does anyone have the same problems? Is there a way to solve it? any link to proper documentation would help!
Thank you very much.
24 August 2010 at 1:02 PM
Hi Yul,
the problem is indeed caused by ntheorem. But that package provides an option that takes care of it, just add amsmath as option:
24 August 2010 at 5:02 PM
Hi all,
I want latex to generate footnote consecutive numbers automatically through out my document. I tried to use this command \footenote{text}.But it only generate consecutive numbers only with in a page. In a new page it always begins with 1 every time. I want all the footnotes through out the document to have different numbering say 1, 2…. I can do that manually using \footenote[#]{text}. But it seems cumbersome. Can any one help me how to do it?
24 August 2010 at 5:53 PM
Hi Alem,
which document class do you use? Do you load the footmisc package or any other footnotes-related package?
25 August 2010 at 7:36 AM
Hi Stefan,
I use the document class scrbook. I loaded the footmisc package. But, it has not helped me.
29 August 2010 at 1:26 PM
Hi Alem,
that’s not the default behavior of scrbook and footmisc. In this example the second footnote will fall onto the second page and will get number 2:
So, there’s information missing. Perhaps post your preamble, I guess it’s caused by an option or package you didn’t mention. For instance, footmisc provides the option perpage, this causes such numbering per page. Or send me the preamble or a document by email to check.
Stefan
30 August 2010 at 10:54 AM
Hi Stefan,
Here is my preamble
\documentclass[12pt,a4paper,twoside,openright,BCOR=1cm]{scrbook}
\usepackage{footmisc}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{lmodern}
\usepackage{fixltx2e}
\usepackage{titlesec}
\usepackage{amscd}
\usepackage{amssymb}
%\usepackage[margin=4cm]{geometry}
%\usepackage[a4paper]{geometry}
\usepackage{amstext}
\usepackage{mathrsfs}
\usepackage{relsize}
\usepackage{mathptmx}
\usepackage{makeidx}
\usepackage{fancyhdr}
\usepackage{textcomp}
\usepackage[T1]{fontenc}
\usepackage{verbatim, amsmath, amsfonts, amssymb, amsthm}
\usepackage{microtype}
\usepackage{setspace}
\usepackage{pfnote}
\usepackage{fnpos}
\usepackage[final]{hyperref}
\hypersetup{colorlinks=true, linkcolor=blue, anchorcolor=blue,
citecolor=red, filecolor=blue, menucolor=blue, pagecolor=blue,
urlcolor=blue}
Alem
30 August 2010 at 11:23 AM
Hi Alem,
just remove that line:
\usepackage{pfnote}
The package pfnote resets the footnote counter for each page. As I believe that this is its only purpose, you would not need it.
Stefan
31 August 2010 at 8:16 AM
Thank you very much Stefan. I removed that, and got what i exactly want. you have been really of a great help!
Alem