# aligned environment of amsmath vs array environment

Today I found out the existence of the aligned environment of the amsmath package. However, I can't see the advantage of using it instead of the array environment from the example provided in amsldoc.pdf, Sec.3.7. In particular, as I can just get almost the same result by using the array environment:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\left.\begin{aligned}
B'&=-\partial\times E,\\
E'&=\partial\times B - 4\pi j,
\end{aligned}
\right\}
\end{equation*}

\begin{equation*}
\left.\begin{array}{l}
B'=-\partial\times E,\\
E'=\partial\times B - 4\pi j,
\end{array}
\right\}
\end{equation*}

\end{document}


giving the output

What are the differences, and why should one be preferred over the other in this context?

aligned basically gives you a sequence of r@{}l column pairs; thus there is no spacing between the two columns in a pair. However, a trick adjusts things so that x&=y gives the right spacing around the equals sign, or any other relation symbol, which is where usually alignment points are desired.

Some control is made so that lines aren't vertically too near, which isn't done in array. Here's a visual comparison. Note what must be done differently in array: one has to add {} before the = and use \dfrac.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\!\begin{aligned} a&=bbb & c&=\frac{x}{y} \\ aa&=bbbb & cc&=\frac{x}{y} \end{aligned}
$\begin{array}{@{}r@{}l@{\quad}@{}r@{}l@{}} a&{}=bbb & c&{}=\dfrac{x}{y} \\ aa&{}=bbbb & cc&{}=\dfrac{x}{y} \end{array}$
\end{document}


(The \! is due to a glitch in amsmath that is kept for historical reasons; however it doesn't hurt much if no comparison has to be made. Newer versions of amsmath don't need it.)

In conclusion, array and aligned are different tools, each one has its pros and cons, depending on the problem that has to be solved: array is more flexible in terms of horizontal alignment of cells, aligned has other features that make it preferable in some situations. Don't forget alignedat, that allows to specify the horizontal space between column pairs.

Also to be noticed is that align and alignat have no array counterpart: with array one can't number lines (easily, at least).

• So if I do not write the \!, an equation with width of linewidth issues a warning (and maybe sticks out to the right that amount)?
– jjdb
May 2, 2013 at 10:06
• @jjdb A thin space is added (1/6 of a em, so it shouldn't really be a concern). May 2, 2013 at 10:09
• Ok, but in two-column articles one has often to fight to get the equation into one line. I encountered a few times the situation where adding a \! somewhere command made the black boxes from the draft mode vanish
– jjdb
May 2, 2013 at 13:02
• @Zelphir array is for, well, arrays; for aligning different equations, aligned or similar environments are better. Sep 16, 2016 at 14:52
• @Zelphir You're right: matrices are built with array (but it's better to use the appropriate amsmath special environments); array is more general and can come handy in case some complex alignment is needed. Sep 18, 2016 at 8:12

Note that in your example you have not used an alignment point & The = are aligned just because B and E happen to have the same width. If you changed your example, for example used W or a different expression altogether then you would have to work a bit harder to get the correct spacing around =.

• Is this a typo in your answer as this question is about the aligned environment, not about the align environment.
– jjdb
May 2, 2013 at 12:59
• @jjdb I can't reconstruct my thought process: I'll delete the last sentence, thanks:-) May 2, 2013 at 13:24

Well, for one, notice the difference in spacing and the squeezing of the two lines. I am not aware of the internal mechanism that distinguishes the two, but in terms of usage, aligned is far simpler and easier, allows me to focus on the equation rather than array elements. A similar difference can be noticed in the matrix environments bmatrix, pmatrix, and vmatrix in amsmath vs creation of such matrices manually using various brackets and the array environment.