Aligned equations in LaTeX
Updated:
Several equations aligned at the = sign are written with the align environment. The & character marks the alignment point and \\ ends a row. align numbers every equation, align* numbers none.
Step-by-step derivation
\begin{aligned} (a+b)^2 &= (a+b)(a+b) \\ &= a^2 + 2ab + b^2 \end{aligned}aligned works inside $$ ... $$ or \[ ... \] and keeps the whole block in one display. Put the & just before each equals sign so the rows line up there.
Copying this from handwritten notes? Snap a photo of the page and CamteX turns the formulas into LaTeX. Try it free
Numbered equations in a document
\begin{align}
F &= ma \label{eq:newton} \\
E &= mc^2 \nonumber
\end{align}align numbers each row. \nonumber or \notag removes the number from one row, and a \label belongs on its own row, before the \\ that ends it.
Equations side by side
\begin{aligned} x &= 1, & y &= 2 \\ z &= 3, & w &= 4 \end{aligned}Every second & starts a new column: the first of each pair aligns, the next one separates columns. It is a compact way to list several short results.
Breaking a long equation
\begin{aligned} f(x) &= a_0 + a_1 x + a_2 x^2 \\ &\quad + a_3 x^3 + a_4 x^4 \end{aligned}When one equation is too wide for the page, break it before a plus or minus sign and indent the continuation with \quad after the &.
One number for a derivation
\begin{equation}
\begin{split}
(a+b)^3 &= (a+b)(a+b)^2 \\
&= a^3 + 3a^2 b + 3ab^2 + b^3
\end{split}
\end{equation}split inside equation gives a multi-line derivation a single number, centred vertically. Use it when the steps lead to one result you cite once.
Common mistakes
- Nesting align inside $$...$$: align is already display math and fails inside $$.
- The old eqnarray environment: it leaves too much space around the equals sign.
- An & on only some rows: the rows without it start at the left edge and the equals signs no longer line up.
- A blank line inside align: compilation stops with a Paragraph ended error.
See also
Don't want to memorize commands?
Draw a formula or paste a screenshot, and CamteX turns it into ready LaTeX.