Building on the math basics, this guide covers advanced equation formatting, multi-line equations, alignment, and professional mathematical typesetting.
Single Equations
Basic Display Equations
\documentclass{article}
\usepackage{amsmath}
\begin{document}
% Simple display equation
\[ E = mc^2 \]
% With equation number
\begin{equation}
E = mc^2
\end{equation}
% Without equation number
\begin{equation*}
E = mc^2
\end{equation*}
% Reference an equation
\begin{equation}\label{eq:energy}
E = mc^2
\end{equation}
As shown in Equation \ref{eq:energy}, energy and mass are related.
% Using \eqref for parentheses
As shown in Equation \eqref{eq:energy}...
\end{document}
Rendered output:
\[ E = mc^2 \]
→ E = mc² (centered display)
\begin{equation} E = mc^2 \end{equation}
→ E = mc² (numbered equation)
Equation Numbering Control
% Suppress numbering for specific equation
\begin{equation}
a^2 + b^2 = c^2 \nonumber
\end{equation}
% Custom numbering
\begin{equation}
F = ma \tag{Newton's 2nd Law}
\end{equation}
% Numbered with custom tag
\begin{equation}
e^{i\pi} + 1 = 0 \tag{$\star$}
\end{equation}
% Subequations
\begin{subequations}
\begin{equation}
x + y = 5
\end{equation}
\begin{equation}
2x - y = 1
\end{equation}
\end{subequations}
Multi-line Equations
Split Environment
For single equations that are too long:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{split}
(a + b)^4 &= (a + b)^2(a + b)^2 \\
&= (a^2 + 2ab + b^2)(a^2 + 2ab + b^2) \\
&= a^4 + 4a^3b + 6a^2b^2 + 4ab^3 + b^4
\end{split}
\end{equation}
% Left-aligned split
\begin{equation}
\begin{split}
\text{LHS} &= \text{some long expression} \\
&\quad + \text{continuation} \\
&\quad + \text{more terms} \\
&= \text{RHS}
\end{split}
\end{equation}
\end{document}
Rendered output:
(a + b)⁴ = (a + b)²(a + b)²
= (a² + 2ab + b²)(a² + 2ab + b²)
= a⁴ + 4a³b + 6a²b² + 4ab³ + b⁴ (2)
Multline Environment
For very long single equations:
\begin{multline}
\int_0^1 \biggl\{ \sum_{i=1}^n x_i^2 + \sum_{j=1}^m y_j^2
+ \sum_{k=1}^p z_k^2 \biggr\} \, dx \\
+ \int_1^2 \biggl\{ \sum_{i=1}^n x_i^3 + \sum_{j=1}^m y_j^3
+ \sum_{k=1}^p z_k^3 \biggr\} \, dx \\
= \text{some complicated result}
\end{multline}
% Control positioning
\begin{multline}
\text{First line flush left} \\
\text{Middle lines centered} \\
\shoveleft{\text{This line shoved left}} \\
\shoveright{\text{This line shoved right}} \\
\text{Last line flush right}
\end{multline}
Aligned Equations
Align Environment
The most versatile environment for multiple equations:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
% Basic alignment
\begin{align}
2x + 3y &= 7 \\
5x - 2y &= 4
\end{align}
% Multiple alignment points
\begin{align}
x &= a + b &\qquad y &= c + d \\
2x &= 2(a + b) &\qquad 3y &= 3(c + d)
\end{align}
% Without numbering
\begin{align*}
\sin^2\theta + \cos^2\theta &= 1 \\
1 + \tan^2\theta &= \sec^2\theta \\
1 + \cot^2\theta &= \csc^2\theta
\end{align*}
% Selective numbering
\begin{align}
a &= b + c \\
d &= e + f \nonumber \\
g &= h + i
\end{align}
\end{document}
Rendered output:
Aligned Within Equation
% For alignment within a single equation number
\begin{equation}
\begin{aligned}
f(x) &= (x+a)(x+b) \\
&= x^2 + (a+b)x + ab
\end{aligned}
\end{equation}
% Multiple aligned blocks
\begin{equation}
\left\{
\begin{aligned}
x + y + z &= 1 \\
2x - y + 3z &= 0 \\
x - 2y - z &= 4
\end{aligned}
\right.
\end{equation}
Equation Arrays
Eqnarray (Deprecated)
Note: eqnarray
is deprecated. Use align
instead. Shown here for reference only.
Array Environment
For complex layouts:
\begin{equation}
\begin{array}{lcl}
f(x) &=& (x+1)^2 \\
&=& x^2 + 2x + 1
\end{array}
\end{equation}
% Multiple columns
\begin{equation}
\begin{array}{ccc}
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33}
\end{array}
\end{equation}
Cases and Piecewise Functions
Cases Environment
\documentclass{article}
\usepackage{amsmath}
\begin{document}
% Basic cases
\begin{equation}
f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\
-x^2 & \text{if } x < 0
\end{cases}
\end{equation}
% Multiple conditions
\begin{equation}
\text{sgn}(x) = \begin{cases}
1 & \text{if } x > 0 \\
0 & \text{if } x = 0 \\
-1 & \text{if } x < 0
\end{cases}
\end{equation}
% Nested cases
\begin{equation}
f(x,y) = \begin{cases}
\begin{cases}
1 & \text{if } y > x \\
0 & \text{if } y = x
\end{cases} & \text{if } x \geq 0 \\
-1 & \text{if } x < 0
\end{cases}
\end{equation}
% Left cases
\begin{equation}
\begin{rcases}
x^2 + y^2 = 1 \\
x + y = 0
\end{rcases} \text{defines a curve}
\end{equation}
\end{document}
Rendered output:
x² if x ≥ 0
-x² if x < 0 (5)
1 if x > 0
0 if x = 0
-1 if x < 0 (6)
Gathered and Centered Equations
% Multiple centered lines with one number
\begin{equation}
\begin{gathered}
(a + b)^2 = a^2 + 2ab + b^2 \\
(a - b)^2 = a^2 - 2ab + b^2 \\
(a + b)(a - b) = a^2 - b^2
\end{gathered}
\end{equation}
% Within text
The identities $\begin{gathered}
\sin^2\theta + \cos^2\theta = 1 \\
\tan\theta = \frac{\sin\theta}{\cos\theta}
\end{gathered}$ are fundamental.
Advanced Alignment
Complex Alignment Patterns
% Aligning equals signs and operators
\begin{align}
f(x) &= x^2 + 2x + 1 \\
&= (x + 1)^2 \\
&> 0 \quad \text{for all } x \neq -1
\end{align}
% Multiple columns
\begin{align}
a_1 &= b_1 + c_1 & a_2 &= b_2 + c_2 \\
d_1 &= e_1 + f_1 & d_2 &= e_2 + f_2
\end{align}
% Alignment with text
\begin{align}
2x + 3 &= 7 & &\text{(given)} \\
2x &= 4 & &\text{(subtract 3)} \\
x &= 2 & &\text{(divide by 2)}
\end{align}
Intertext and Shortintertext
\begin{align}
a &= b + c \\
&= d + e + f
\intertext{Now we substitute the known values:}
&= 1 + 2 + 3 \\
&= 6
\end{align}
% Shorter spacing
\begin{align}
x^2 + y^2 &= r^2
\shortintertext{and}
x &= r\cos\theta \\
y &= r\sin\theta
\end{align}
Boxed and Highlighted Equations
% Simple box
\begin{equation}
\boxed{E = mc^2}
\end{equation}
% Colored box
\usepackage{xcolor}
\begin{equation}
\colorbox{yellow}{$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$}
\end{equation}
% Framed important result
\begin{equation}
\boxed{
\int_{-\infty}^{\infty} e^{-x^2} \, dx = \sqrt{\pi}
}
\end{equation}
% Highlight part of equation
\begin{equation}
f(x) = \underbrace{x^2 + 2x}_{\text{quadratic}} +
\overbrace{3x + 4}^{\text{linear}}
\end{equation}
Equation Spacing
Manual Spacing in Equations
% Spacing commands
\begin{align}
f(x) &= x^2+2x+1 \\ % No space
f(x) &= x^2 + 2x + 1 \\ % Normal space
f(x) &= x^2\,+\,2x\,+\,1 \\ % Thin space
f(x) &= x^2\:+\:2x\:+\:1 \\ % Medium space
f(x) &= x^2\;+\;2x\;+\;1 \\ % Thick space
f(x) &= x^2\quad+\quad2x\quad+\quad1 % Quad space
\end{align}
% Negative space
\begin{equation}
\int\!\!\!\int f(x,y) \, dx \, dy % Bring integral signs closer
\end{equation}
Best Practices
Equation guidelines:
- Consistency: Use the same alignment style throughout
- Readability: Don’t over-align; prioritize clarity
- References: Label important equations for cross-referencing
- Spacing: Use
\,
before differentials in integrals
- Breaking: Break long equations at operators (+, -, =)
- Grouping: Use
subequations
for related equations
Common Patterns
System of Equations
% Using array
\begin{equation}
\left\{
\begin{array}{rcrcrcr}
2x & + & 3y & - & z & = & 4 \\
x & - & y & + & 2z & = & 1 \\
3x & + & y & - & z & = & 0
\end{array}
\right.
\end{equation}
% Using aligned
\begin{equation}
\left\{
\begin{aligned}
2x + 3y - z &= 4 \\
x - y + 2z &= 1 \\
3x + y - z &= 0
\end{aligned}
\right.
\end{equation}
Rendered output:
Derivations
\begin{align}
(x + y)^2 &= (x + y)(x + y) \\
&= x(x + y) + y(x + y) \\
&= x^2 + xy + yx + y^2 \\
&= x^2 + 2xy + y^2
\end{align}
Rendered output:
(x + y)² | = | (x + y)(x + y) | (8) |
| = | x(x + y) + y(x + y) | (9) |
| = | x² + xy + yx + y² | (10) |
| = | x² + 2xy + y² | (11) |
Quick Reference
Environment | Purpose | Numbering |
---|
equation | Single equation | Yes |
equation* | Single equation | No |
align | Multiple aligned equations | Yes (each) |
align* | Multiple aligned equations | No |
split | Split long equation | One number |
multline | Very long equation | One number |
gather | Centered equations | Yes (each) |
cases | Piecewise functions | Within equation |