Skip to main content
Back to guides
6 min read

How to Align Equations & Systems in LaTeX (align, aligned, cases)

Master multi-line equation alignment in LaTeX: learn amsmath align, aligned environments, systems of equations with cases, and anchor point & formatting rules.

By Alex Chen

In scientific publishing and technical problem sets, single-line equations are the exception rather than the norm. Real-world mathematical proofs, algebraic simplifications, and system models inevitably require multi-step derivations that span multiple lines.

Without the proper tools, multi-line typesetting is one of the most frustrating aspects of LaTeX. This guide breaks down the core alignment environments provided by the American Mathematical Society’s amsmath package, examines nested sub-environments, and demonstrates how to typeset piecewise functions and systems of equations with publication-grade precision.


1. The Multi-Line Equation Challenge

New LaTeX authors instinctively try inserting double backslashes (\\) into a standard equation environment when an expression grows too long:

% THIS CAUSES A COMPILATION ERROR:
\begin{equation}
  f(x) = (x + 2)^2 \\
       = x^2 + 4x + 4
\end{equation}

Compiling this snippet fails immediately with an error:

! LaTeX Error: Something's wrong--perhaps a missing \item.

Standard LaTeX equation and displaymath environments are strictly single-line containers. They do not possess a multi-row layout grid or alignment mechanics.

To align expressions vertically across rows, the amsmath package is required. Modern LaTeX documents should always include it in the preamble:

\usepackage{amsmath}

With amsmath imported, you gain access to the workhorse alignment environments: align, align*, aligned, cases, gather, and multline.


2. The Core Workhorse: align and align*

The align environment creates a structured display grid where equations are aligned horizontally using the ampersand character (&) as an anchor point.

align vs. align*: Numbering Behavior

  • \begin{align}: Generates a sequentially numbered equation on every individual row by default.
  • \begin{align*}: Suppresses numbering across all lines, creating clean unnumbered derivations.
% Unnumbered step-by-step derivation:
\begin{align*}
  \int x e^{2x} \, dx &= \frac{1}{2} x e^{2x} - \int \frac{1}{2} e^{2x} \, dx \\
                      &= \frac{1}{2} x e^{2x} - \frac{1}{4} e^{2x} + C \\
                      &= \frac{1}{4} e^{2x} (2x - 1) + C
\end{align*}

The Anchor Operator (&)

The ampersand (&) sets the vertical reference axis across lines. By convention, place the & immediately before the relational or equality operator:

  • Use &= (not =&) so LaTeX properly computes mathematical spacing around binary relations.
  • Use &\leq, &\approx, or &\implies for inequalities and deductions.
\begin{align*}
  A &\approx 3.14159 \\
  B &\leq C + D
\end{align*}

Aligning Multiple Parallel Columns

You can typeset side-by-side equations across columns within a single align block. The align environment alternates between alignment points and column separators:

  • Odd & (1st, 3rd, 5th…): Specifies where the column aligns.
  • Even & (2nd, 4th, 6th…): Separates independent equation columns, adding automatic horizontal spacing.
\begin{align*}
  x &= 1 & y &= 2 & z &= 3 \\
  2x &= 2 & 3y &= 6 & 4z &= 12
\end{align*}

The Golden Rule: No Trailing \\ on the Final Line

One of the most pervasive beginner bugs is appending \\ to the last row of an align block:

% INCORRECT: Notice the trailing \\ on the last line
\begin{align}
  a &= b + c \\
  d &= e + f \\  % <--- DO NOT DO THIS!
\end{align}

Placing a line break on the final row signals LaTeX to generate an extra line. In an align environment, this inserts an unsightly empty row with an unwanted equation number (2). Always omit \\ from the final equation in the block.


3. Fine-Grained Numbering: \notag and \tag{...}

When using the numbered align environment, you frequently want numbers on only key conclusion lines rather than every intermediate algebraic manipulation.

Suppressing Specific Lines with \notag

Append \notag (or \nonumber) right before the line break (\\) on any line you wish to silence:

\begin{align}
  \mathcal{L} &= \frac{1}{2} m \dot{x}^2 - V(x) \notag \\
  \frac{d}{dt}\left(\frac{\partial \mathcal{L}}{\partial \dot{x}}\right) - \frac{\partial \mathcal{L}}{\partial x} &= 0 \notag \\
  m \ddot{x} + \nabla V(x) &= 0 \label{eq:newton_second}
\end{align}

In this 3-line derivation, only the final equation receives an equation number and an anchor for \eqref{eq:newton_second}.

Custom Labels with \tag{...}

To assign a custom non-numeric label (such as an asterisk, dagger, or Roman numeral), use \tag{...}:

\begin{equation*}
  e^{i\pi} + 1 = 0 \tag{Euler}
\end{equation*}

This renders the equation tagged with (Euler) on the right margin instead of a sequential number.


4. Sub-Alignment with aligned (Nested Math)

Understanding the distinction between align and aligned is crucial for advanced LaTeX documents:

  • align is an outer display environment. It creates an independent display block and cannot be placed inside another math environment.
  • aligned is an inner sub-environment. It does not create an outer display block on its own; it must reside inside math mode (such as equation, \[ ... \], or bracketed matrix delimiters).

Practical Use Case 1: Single Number for a Multi-Step Proof

If you have a 4-line derivation and want exactly one vertically centered equation number for the entire group, nest aligned inside equation:

\begin{equation}
  \begin{aligned}
    S_n &= \sum_{k=1}^n k \\
        &= 1 + 2 + \dots + n \\
        &= \frac{n(n + 1)}{2}
  \end{aligned}
  \label{eq:gauss_sum}
\end{equation}

The aligned block organizes the step derivation at the = sign, while the enclosing equation environment applies a single centered identifier (1).

Practical Use Case 2: Braced Equation Systems

To represent simultaneous equations grouped with a left brace, enclose an aligned block between \left\{ and \right.:

\begin{equation*}
  \left\{
  \begin{aligned}
    3x + 2y - z &= 1 \\
    2x - 2y + 4z &= -2 \\
    -x + \frac{1}{2}y - z &= 0
  \end{aligned}
  \right.
\end{equation*}

Note on \right.: Every \left\{ in LaTeX requires a matching right delimiter. If you do not want a visible closing brace on the right, use the invisible delimiter \right..


5. Piecewise Functions with \begin{cases}

For piecewise-defined equations, conditional functions, or boundary value formulations, amsmath provides the dedicated cases environment.

cases automatically supplies an appropriately scaled left curly brace ({) and configures a two-column layout:

  1. Column 1: The mathematical formula.
  2. Column 2: The condition or domain predicate.

Example: Absolute Value Function

\[
|x| =
\begin{cases}
  x  & \text{if } x \ge 0, \\
  -x & \text{if } x < 0.
\end{cases}
\]

Example: 3-Condition Step Function

\[
f(x) =
\begin{cases}
  0            & \text{for } x < -1, \\
  \frac{1}{2}(x + 1) & \text{for } -1 \le x \le 1, \\
  1            & \text{for } x > 1.
\end{cases}
\]

Typography Guard: Always wrap explanatory text (such as “if”, “for”, “otherwise”) inside \text{...}. Without \text{...}, LaTeX treats “if” as variables $i \cdot f$ in italic math mode with improper spacing.


6. Prose Between Steps: \intertext vs. \shortintertext

When authoring long mathematical derivations, writers frequently need to insert a full sentence of commentary between consecutive steps.

The Naive Mistake

Beginners often terminate their align block, type a regular paragraph of text, and then open a brand-new align block:

% FLAWED PATTERN: Alignment anchors will not line up across blocks!
\begin{align*}
  A &= 2x^2 + 5x - 3
\end{align*}
Factoring the quadratic polynomial:
\begin{align*}
  A &= (2x - 1)(x + 3)
\end{align*}

Because each align* environment calculates its column positions independently based on the widest element in its own block, the equals signs (=) will not align with each other.

The Solution: \intertext

Use \intertext{...} directly inside an existing align block:

\begin{align*}
  f(x) &= x^4 - 5x^2 + 4 \\
  \intertext{We substitute $u = x^2$ to obtain a standard quadratic form:}
  g(u) &= u^2 - 5u + 4 \\
       &= (u - 1)(u - 4) \\
  \intertext{Substituting $x^2$ back into the factored expression yields:}
  f(x) &= (x^2 - 1)(x^2 - 4) \\
       &= (x - 1)(x + 1)(x - 2)(x + 2)
\end{align*}

\intertext drops temporarily back into text mode across the full page width, while preserving the exact horizontal alignment anchor across all sections of the derivation.

Tip for Tighter Padding: If standard \intertext leaves too much vertical whitespace, import \usepackage{mathtools} and use \shortintertext{...} instead.


7. Comparison Cheat Sheet: Which Environment to Use

Environment Standalone Display? Numbering Behavior Best Used For
align Yes Numbers every line by default Formal derivations where steps are cited
align* Yes Unnumbered Standard step-by-step mathematical derivations
aligned No (Sub-environment) Inherits parent container Multi-step math sharing one number, or inside brackets
cases No (Sub-environment) Inherits parent container Piecewise functions and boundary specifications
gather Yes Numbers every line Multiple independent equations without horizontal alignment
multline* Yes Unnumbered A single expression too wide for one line

8. Pro Tips & Common Troubleshooting

  1. Unbalanced Delimiter Errors: If you encounter ! Extra }, or forgotten \right, check for unclosed \left\{ or \left[. Every \left must match a corresponding \right (use \right. for invisible closures).
  2. Double Ampersand Column Spacing: Remember that in align, odd ampersands (&) anchor alignment and even ampersands (&&) separate columns. If equations look glued together horizontally, add an extra & to introduce column padding.
  3. Punctuation Inside Display Environments: Treat display equations as grammatical components of your paragraphs. Place periods, semicolons, and commas directly before the closing delimiter or before \end{align}.
  4. Interactive Syntax Verification: Complex multi-row derivations with nested aligned and cases blocks can be difficult to debug from compiler log files alone. Use our interactive LaTeX Equation Studio to experiment with multi-line environments with real-time visual KaTeX preview, error diagnostics, and 1-click MathML and vector SVG export.
Tags:#latex#amsmath#equations#align#cases#math