I just learned in eqnarray vs align that eqnarray should be avoided in general. Ok, so I started looking at my documents to get rid of it and (as suggested) use some environment of the amsmath package instead. However, I encountered two situations where this change yields a worse output (IMHO) than with eqnarray. This may be due to my lack of knowledge how to do it right, but first I will show the two situations:
The first one is a sequence of (in-)equalities used to prove a bound (as common in, e.g., runtime complexity analysis). This one here is used to show that 2^n does not grow faster than n!.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{eqnarray*}
2^n & = & \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n \text{ times}}\\
& \stackrel{n > 3}{=} & 2 \cdot 2 \cdot 2 \cdot 2 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& = & 16 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& < & 24 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& = & 1 \cdot 2 \cdot 3 \cdot 4 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& \stackrel{n > 3}{\leq} & 1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 \cdot \ldots \cdot n\\
& = & n!
\end{eqnarray*}
\end{document}
It yields the following output:
These are my attempts to use some environment of the amsmath package instead:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
2^n & = \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n \text{ times}}\\
& \stackrel{n > 3}{=} 2 \cdot 2 \cdot 2 \cdot 2 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& = 16 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& < 24 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& = 1 \cdot 2 \cdot 3 \cdot 4 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& \stackrel{n > 3}{\leq} 1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 \cdot \ldots \cdot n\\
& = n!
\end{align*}
\[
\begin{aligned}
2^n & = && \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n \text{ times}}\\
& \stackrel{n > 3}{=} && 2 \cdot 2 \cdot 2 \cdot 2 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& = && 16 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& < && 24 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& = && 1 \cdot 2 \cdot 3 \cdot 4 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& \stackrel{n > 3}{\leq} && 1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 \cdot \ldots \cdot n\\
& = && n!
\end{aligned}
\]
\begin{alignat*}{2}
2^n & = && \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n \text{ times}}\\
& \stackrel{n > 3}{=} && 2 \cdot 2 \cdot 2 \cdot 2 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& = && 16 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& < && 24 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& = && 1 \cdot 2 \cdot 3 \cdot 4 \cdot \underbrace{2 \cdot 2 \cdot \ldots \cdot 2}_{n - 4 \text{ times}}\\
& \stackrel{n > 3}{\leq} && 1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 \cdot \ldots \cdot n\\
& = && n!
\end{alignat*}
\end{document}
The corresponding outputs have the following flaws:
align:
The reduced space between the relation symbols and the terms they connect makes it harder to recognize the steps in this proof. While one can argue whether more space is a good thing here (I read "consistency over all" in one of the documents advocating the avoidance of eqnarray and I do not entirely agree on this - I think readability is more important than consistency while consistency supports readability in most cases but possibly not always), I think it is definitely not the best thing that the relations built with \stackrel are not aligned in a centered way below the other relation symbols. The latter point is also a flaw of all the other attempts to use an environment of the amsmath package (which is to be expected as these environments only offer columns being left- or right-aligned but not centered - at least I did not find a similar environment offering a centered column).
aligned:
While we do have more space on the right of the relation symbols, we have less space on the left of them.
alignat:
This is even worse than aligned since now the spacing is not only different between left and right of the relation symbols but we also have almost no space between the relation symbols built with \stackrel and the next term.
The second situation is the definition of substitutions as comma-separated lists of replacements in square brackets (a notation quite common in, e.g., term rewriting or logic programming). If these definitions are too long such that we need to break them, the environments of the amsmath package do not succeed in aligning the second line correctly while keeping the same amount of space left and right of the = symbol:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{eqnarray*}
\sigma & = & [x_1/t_1,x_2/t_2,\\
& & x_3/t_3,x_4/t_4]
\end{eqnarray*}
\begin{align*}
\sigma & = [x_1/t_1,x_2/t_2,\\
& x_3/t_3,x_4/t_4]
\end{align*}
\begin{align*}
\begin{split}
\sigma & = [x_1/t_1,x_2/t_2,\\
& x_3/t_3,x_4/t_4]
\end{split}
\end{align*}
\[
\begin{aligned}
\sigma & = && [x_1/t_1,x_2/t_2,\\
& && x_3/t_3,x_4/t_4]
\end{aligned}
\]
\begin{alignat*}{2}
\sigma & = && [x_1/t_1,x_2/t_2,\\
& && x_3/t_3,x_4/t_4]
\end{alignat*}
\end{document}
eqnarray:
align:
Here, the two versions with and without the use of split yield the same output. The spacing around = is consistent but the alignment of the second line is wrong.
aligned:
Here, the alignment is ok, but the spacing is inconsistent.
alignat:
Again, the alignment is ok but the spacing is inconsistent.
So my question is: How can these two situations be handled without using eqnarray yielding an output which is at least as readable as the versions using it and with a similar (or less) amount of code?
Of course, one can use array and customize it accordingly, but what would be the point of doing so in preference of using the existing eqnarray? Also, in Aligning a split up equation not at equal sign (which is similar to my second situation) the only answer suggests to use \phantom in combination with align to fix the alignment. While this is of course possible, it is definitely more tedious than using eqnarray in such a situation as described above.












eqnarrayis wrong anyway, becauseeqnarraymust *never* be used: its output is bad and it doesn't cooperate well with some packages (notablyhyperrefandcleveref). – egreg Dec 30 '15 at 14:43eqnarraybetter than that ofalign(at least in the form I tried to use it). My question is not to improve the output of the versions usingeqnarraybut to come up with alternatives that do not use it and yield an output which is at least as good. I understand that there are many problems witheqnarraybut avoiding it just for the sake of avoiding it does not make sense to me. In these situations described here, I do not have any problems withhyperreforcleverefor whatsoever. – cryingshadow Dec 30 '15 at 14:48