Aligned equations are a table with two jobs: & marks the column that must line up, and \\ ends a row. Almost every "align does not work" question is one of those two characters in the wrong place. The environment name is the second trap — documents use align, the web needs the inner aligned — and the neighbouring multi-row structures are Systems of Equations and Piecewise Functions.
Which one to use
alignedalign\nonumber& … &\text{…}\intertext in documents.\begin{cases}The commands
\begin{aligned} 2x + 3 &= 7 \\ x &= 2 \end{aligned}
\begin{aligned} y &= (x+1)^2 \\ &= x^2 + 2x + 1 \end{aligned}
\begin{aligned} a &= 1 \\ ab &= 2 \end{aligned}
\begin{aligned} x &= 1 && y &= 2 \\ x^2 &= 4 && y^2 &= 8 \end{aligned}
\text{} so it is set upright instead of as multiplied variables. \begin{aligned} V &= \pi r^2 h \\ &= \frac{\pi d^2 h}{4} \end{aligned}
\begin{gathered} P = 2(l + w) \\ A = lw \end{gathered}
\begin{array}{rcl} x+1 &=& 3 \\ y-2 &=& 5 \end{array}
\substack; a bare \\ inside _{} breaks the formula. \sum_{\substack{1\le i\le n \\ i \text{ odd}}} a_i
\begin{aligned} a &= b \\ c &= d \end{aligned}
Worked examples
Solving in steps
\begin{aligned} 3x - 5 &= 34 \\ 3x &= 39 \\ x &= 13 \end{aligned}
Each line drops the completed left-hand work and repeats the anchor, which is what keeps the chain readable.
Expanding then factoring
\begin{aligned} (x+2)(x-3) &= x^2 - x - 6 \\ &= (x-3)(x+2) \end{aligned}
Starting a continuation line with &= is the convention for "this is still the same expression".
Two systems side by side
\begin{aligned} 2a + b &= 5 && a - b &= 1 \\ a &= 2 && b &= 1 \end{aligned}
Four anchors in a row: the pair of && acts as the gutter between the two columns.
A tall derivation inline
f(x) = \begin{cases} x^2 & x \ge 0 \\ -x^2 & x < 0 \end{cases}
When the block is a definition rather than a chain of equalities, cases already handles the alignment for you.
Common mistakes
- Writing
\begin{align}into a browser maths renderer. It is a top-level LaTeX environment; KaTeX and MathJax wantalignedwrapped in math delimiters. - Forgetting the double backslash. Without
\\every line collapses onto one row and the ampersands start acting as column separators in a single overloaded line. - Adding
=at the anchor on the first line only. Either every line carries the relation or the columns stop meaning anything. - Ending the last row with
\\. That produces an empty trailing row and, in numbered documents, a stray equation number.
Questions about this notation
What is the difference between align and aligned?
Where exactly does the & go?
How do I stop one line being numbered?
\nonumber at the end of that row, or use the starred form align* for a block with no numbers at all. Inside aligned there is no numbering to suppress.How do I align at more than one place, or put text between aligned lines?
& is one alignment point and they alternate right-aligned then left-aligned, so a &= b &= c lines up two equals signs on one row. Prose that should sit between rows goes in \intertext{...}, which keeps the numbering of the rows around it; prose inside a row goes in \text{...}. Both are amsmath.Keep reading
Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.