Skip to content
Topos Uranos

Summary

This lesson teaches how to typeset formulas that take up several lines with the environments of amsmath and mathtools. It shows why several displayed formulas should not be stacked and why eqnarray should not be used, since its spacing around the equals sign is faulty; it presents align and align*, with the sign & as the alignment point, \\ as the end of a line, several columns of aligned pairs, and the numbering of each line, which is suppressed with \notag, replaced with \tag and referred to with \label and \eqref; it distinguishes gather, multline and split, and the inner blocks aligned and gathered; it typesets piecewise definitions with cases and dcases; it inserts text with \intertext and \shortintertext; it writes matrices with their delimiters, their dots and their vertical rule; it numbers groups with subequations; it allows a long display to break across pages; and it ends with the typical errors, read in real logs, and with what is best avoided.

Learning objectives

  1. Explain why a chain of equalities is typeset in a single alignment environment, and not in stacked displayed formulas or in eqnarray.
  2. Typeset with align calculations and systems of one or several columns, placing each & before the sign it aligns, and decide which lines are numbered and how they are referred to.
  3. Choose between align, gather, multline, split, aligned and gathered according to the structure of the formula and the number it must carry, justifying the choice.
  4. Typeset piecewise definitions, matrices with their delimiters and augmented matrices, and insert text without breaking the alignment.
  5. Diagnose the typical errors of the alignment environments, both those the log reports and those that can only be seen in the result.

Why loose formulas are not stacked

The lesson on inline and displayed formulas showed that a displayed formula is written between \[ and \], or in the equation environment if it carries a number. Both typeset one centred line. Now, a good part of written mathematics does not fit on one line, nor does it consist of a single relation: a calculation advances through a chain of equalities, a system gathers several equations, a definition distinguishes cases. In all of them the reader needs to see, one below the other, the signs that articulate the reasoning, and it follows that the typesetting must align them.

The immediate temptation is to stack several displayed formulas, one per step. Each is centred on its own, so the equals signs land wherever the width of each line puts them, and between them is left the space that belongs to two separate displays, not to a single one. The second temptation is the eqnarray environment, which LaTeX has had since its beginnings and which still appears in many manuals: it aligns, but it sets the central sign as a column of its own, separated by the space of a table, wider than the space that belongs to a relation, so that the same equalities look loose. The following example typesets the same calculation in three ways.

ExampleOne calculation, three typesettings
LaTeX code
Stacked displayed formulas:\[ (a+b)^2 = (a+b)(a+b) \]\[ = a^2 + ab + ba + b^2 \]\[ = a^2 + 2ab + b^2 \]With \texttt{eqnarray*}:\begin{eqnarray*}(a+b)^2 &=& (a+b)(a+b) \\        &=& a^2 + 2ab + b^2\end{eqnarray*}With \texttt{align*}:\begin{align*}(a+b)^2 &= (a+b)(a+b) \\        &= a^2 + 2ab + b^2\end{align*}
Result
Result

In the first typesetting, the equals signs are not one below the other and the lines are separated by large gaps; in the second, the equals sign is isolated between two holes; only the third sets them as relations of one and the same chain. The amsmath package, which the course always loads, offers align and its relatives precisely to replace eqnarray, which should not be used in any new document.