LaTeX Align: Multi-Line Aligned Equations

Putting the & where the columns should meet, how each line ends, and why web maths renderers want aligned rather than align.

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

Situation Write this Because
Multi-line derivation on the web
aligned
Renders in KaTeX, MathJax and LaTeX alike.
A numbered document block
align
Needs amsmath; numbers each line.
One line without a number
\nonumber
Kills the number on that line only.
More than one alignment point
& … &
Each pair of ampersands opens a column.
Words between lines
\text{…}
Inside maths; \intertext in documents.
A brace instead of a number
\begin{cases}
Different structure: see systems.

The commands

What Type this Renders as
Two lines, one anchor The ampersand marks the column that lines up; \ starts the next row.
\begin{aligned} 2x + 3 &= 7 \\ x &= 2 \end{aligned}
\begin{aligned} 2x + 3 &= 7 \\ x &= 2 \end{aligned}
Aligned equals signs Repeat &= on every continuation line and leave the dangling operand out entirely.
\begin{aligned} y &= (x+1)^2 \\ &= x^2 + 2x + 1 \end{aligned}
\begin{aligned} y &= (x+1)^2 \\ &= x^2 + 2x + 1 \end{aligned}
Left-aligned block Anchoring at the relation keeps the terms flush left regardless of width.
\begin{aligned} a &= 1 \\ ab &= 2 \end{aligned}
\begin{aligned} a &= 1 \\ ab &= 2 \end{aligned}
Two columns per line A doubled && separates the pairs, giving two independent alignment points across one row.
\begin{aligned} x &= 1 && y &= 2 \\ x^2 &= 4 && y^2 &= 8 \end{aligned}
\begin{aligned} x &= 1 && y &= 2 \\ x^2 &= 4 && y^2 &= 8 \end{aligned}
Text on its own line Anything verbal goes inside \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{aligned} V &= \pi r^2 h \\ &= \frac{\pi d^2 h}{4} \end{aligned}
Unnumbered document form When lines should stack centred rather than meet at a relation, gathered replaces align.
\begin{gathered} P = 2(l + w) \\ A = lw \end{gathered}
\begin{gathered} P = 2(l + w) \\ A = lw \end{gathered}
Array fallback Column spec letters decide alignment: l, c and r per column, with & between cells.
\begin{array}{rcl} x+1 &=& 3 \\ y-2 &=& 5 \end{array}
\begin{array}{rcl} x+1 &=& 3 \\ y-2 &=& 5 \end{array}
Condition under an operator Multi-line subscripts need \substack; a bare \\ inside _{} breaks the formula.
\sum_{\substack{1\le i\le n \\ i \text{ odd}}} a_i
\sum_{\substack{1\le i\le n \\ i \text{ odd}}} a_i
Line spacing Row height follows display maths; inside a paragraph the whole block lifts the line.
\begin{aligned} a &= b \\ c &= d \end{aligned}
\begin{aligned} a &= b \\ c &= d \end{aligned}

Worked examples

Solving in steps

\begin{aligned} 3x - 5 &= 34 \\ 3x &= 39 \\ x &= 13 \end{aligned}
\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}
\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}
\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}
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 want aligned wrapped 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?
Same layout, different container. align is a displayed environment that numbers each line in a LaTeX document; aligned is a maths box that slots inside $...$ or any other environment and carries no numbering. Web renderers implement aligned only, which is why copied align blocks fail there.
Where exactly does the & go?
Immediately before the character you want lined up. For equations that usually means &= , so the equals signs form a vertical rule. If you want the terms themselves flush, move it to the front of the line.
How do I stop one line being numbered?
In a LaTeX document, put \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?
Each & 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.