Multi-line Equations and Matrices

  • JNext lesson
  • KPrevious lesson
  • FSearch lessons
  • EscClear search

Chapter 4 covered the building blocks. This lesson combines them into the multi-line equations and matrices that research papers and textbooks demand.

Multiline equations in LaTeX have one golden rule: use the amsmath environments (align, gather, cases) and never the ancient eqnarray. This lesson covers aligned derivations, equation groups, piecewise definitions, and every matrix variant you’ll meet in a linear algebra course.

Multi-line Equations

Most real derivations span multiple lines. The amsmath package provides several environments for this.

The align Environment

The workhorse of multi-line math. Lines are aligned at the & character and separated by \\:

\begin{align}
  (x+1)^3 &= (x+1)(x+1)^2 \\
           &= (x+1)(x^2+2x+1) \\
           &= x^3+3x^2+3x+1
\end{align}

Rendered result:

$$ \begin{aligned} (x+1)^3 &= (x+1)(x+1)^2 \\ &= (x+1)(x^2+2x+1) \\ &= x^3+3x^2+3x+1 \end{aligned} $$

Each line gets its own equation number. To suppress numbering on specific lines, add \nonumber before \\. To suppress all numbering, use align*.

The gather Environment

When lines don’t share an alignment point, use gather. Each line is centered independently:

\begin{gather}
  x^2 + y^2 = r^2 \\
  e^{i\theta} = \cos\theta + i\sin\theta \\
  \nabla \cdot \vec{E} = \frac{\rho}{\varepsilon_0}
\end{gather}

Rendered result:

$$ x^2 + y^2 = r^2 $$ $$ e^{i\theta} = \cos\theta + i\sin\theta $$ $$ \nabla \cdot \vec{E} = \frac{\rho}{\varepsilon_0} $$

The multline Environment

For a single equation that’s too long for one line. The first line is left-aligned, the last is right-aligned, and middle lines are centered:

\begin{multline}
  p(x) = x^8 + 3x^7 - 2x^6 + 5x^5 \\
    - 7x^4 + 4x^3 + 11x^2 \\
    - 9x + 13
\end{multline}

Rendered result:

$$ p(x) = x^8 + 3x^7 – 2x^6 + 5x^5 – 7x^4 + 4x^3 + 11x^2 – 9x + 13 $$

Choosing the Right Environment

  • Environment: equation | When to Use: Single equation, numbered
  • Environment: align | When to Use: Multi-line with alignment (derivations, systems)
  • Environment: gather | When to Use: Multi-line without alignment (unrelated equations)
  • Environment: multline | When to Use: One long equation broken across lines
  • Environment: split | When to Use: Multi-line inside a single equation (one number)
  • Environment: aligned | When to Use: Aligned block inside another math environment

    The split Environment

When you want aligned lines but only one equation number, wrap split inside equation:

\begin{equation}
\begin{split}
  \nabla \times \vec{E}
    &= -\frac{\partial \vec{B}}{\partial t} \\
  \nabla \times \vec{B}
    &= \mu_0 \vec{J}
    + \mu_0 \varepsilon_0
    \frac{\partial \vec{E}}{\partial t}
\end{split}
\end{equation}

Rendered result:

$$ \begin{aligned} \nabla \times \vec{E} &= -\frac{\partial \vec{B}}{\partial t} \\ \nabla \times \vec{B} &= \mu_0 \vec{J} + \mu_0 \varepsilon_0 \frac{\partial \vec{E}}{\partial t} \end{aligned} $$

The entire block gets a single equation number on the right, unlike align where each line is numbered separately.

Matrices

The amsmath package provides matrix environments that differ only in their delimiters.

Matrix Types

% No delimiters
$\begin{matrix}
  a & b \\ c & d
\end{matrix}$

% Parentheses
$\begin{pmatrix}
  a & b \\ c & d
\end{pmatrix}$

% Brackets
$\begin{bmatrix}
  a & b \\ c & d
\end{bmatrix}$

% Braces
$\begin{Bmatrix}
  a & b \\ c & d
\end{Bmatrix}$

% Vertical bars (determinant)
$\begin{vmatrix}
  a & b \\ c & d
\end{vmatrix}$

% Double bars (norm)
$\begin{Vmatrix}
  a & b \\ c & d
\end{Vmatrix}$

Rendered results:

No delimiters:

$$ \begin{matrix} a & b \\ c & d \end{matrix} $$

Parentheses:

$$ \begin{pmatrix} a & b \\ c & d \end{pmatrix} $$

Brackets:

$$ \begin{bmatrix} a & b \\ c & d \end{bmatrix} $$

Braces:

$$ \begin{Bmatrix} a & b \\ c & d \end{Bmatrix} $$

Vertical bars (determinant):

$$ \begin{vmatrix} a & b \\ c & d \end{vmatrix} $$

Double bars (norm):

$$ \begin{Vmatrix} a & b \\ c & d \end{Vmatrix} $$

Large Matrices with Dots

For matrices where you need to show a general pattern, use dot commands:

<!--M14-->

Rendered result:

$$ A = \begin{pmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{pmatrix} $$

The three dot commands are:

  • \cdots for horizontal dots (centered)
  • \vdots for vertical dots
  • \ddots for diagonal dots

Augmented Matrices

For augmented matrices (common in linear algebra), use the array environment with a vertical bar in the column specification:

<!--M15-->

Rendered result:

$$ \left[\begin{array}{ccc|c} 1 & 0 & 2 & 3 \\ 0 & 1 & -1 & 5 \\ 0 & 0 & 0 & 0 \end{array}\right] $$

The {ccc|c} column specification means three centered columns, a vertical line, then one more centered column. The \left[ and \right] provide the outer brackets that scale automatically.

Equations under control, theorems and equation numbering adds the formal scaffolding around them. The underlying symbols all live in the notation reference.

Quick answers to common questions:

How do I align a multi-step derivation at the equals signs?

The align environment with & before each = and \\ ending each line: every equals sign stacks in a column, which is exactly how textbook derivations read. Use align* to suppress equation numbers.

Which matrix environment should I use?

pmatrix for parentheses (the default choice), bmatrix for square brackets, vmatrix for determinants. They differ only in the surrounding delimiter; entries are rows separated by \\ with & between columns.

Why is eqnarray considered wrong?

Its spacing around relation signs is inconsistent with everything else in amsmath, and it breaks with long equations. align does everything eqnarray did, correctly. Any tutorial still teaching eqnarray is dating itself.