Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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\}
    \qquad \text{Maxwell’s equations}
\end{equation*}

\begin{equation*}
    \left.\begin{array}{l}
        B'=-\partial\times E,\\
        E'=\partial\times B - 4\pi j, 
    \end{array}
    \right\}
    \qquad \text{Maxwell’s equations}
\end{equation*}

\end{document}

giving the output

enter image description here

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

share|improve this question

3 Answers

up vote 7 down vote accepted

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

enter image description here

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

share|improve this answer
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 at 10:06
@jjdb A thin space is added (1/6 of a em, so it shouldn't really be a concern). – egreg May 2 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 at 13:02
How does one number the lines with aligned? I can't find it in the documentation. – jjdb May 2 at 16:01

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.

share|improve this answer

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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