Chapter 4 covered the building blocks. This lesson combines them into the multi-line equations and matrices that research papers and textbooks demand.
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 singleequation(one number) - Environment:
aligned| When to Use: Aligned block inside another math environmentThe 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:
\cdotsfor horizontal dots (centered)\vdotsfor vertical dots\ddotsfor 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.