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 Display equation: E = m c 2 E = mc^2 E = m c 2 Numbered equation: E = mc^2 \tag{1}
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 2 nd 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 }
2 x - 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 + 2 ab + b^ 2 )(a^ 2 + 2 ab + b^ 2 ) \\
& = a^ 4 + 4 a^ 3 b + 6 a^ 2 b^ 2 + 4 ab^ 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 \begin{aligned}
(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{aligned} \tag{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 }
2 x + 3 y & = 7 \\
5 x - 2 y & = 4
\end { align }
% Multiple alignment points
\begin { align }
x & = a + b & \qquad y & = c + d \\
2 x & = 2 (a + b) & \qquad 3 y & = 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 equations (numbered):
\begin{aligned}
2x + 3y &= 7 \tag{3}\\
5x - 2y &= 4 \tag{4}
\end{aligned} Without numbering:
sin 2 θ + cos 2 θ = 1 1 + tan 2 θ = sec 2 θ 1 + cot 2 θ = csc 2 θ \begin{aligned}
\sin^2\theta + \cos^2\theta &= 1 \\
1 + \tan^2\theta &= \sec^2\theta \\
1 + \cot^2\theta &= \csc^2\theta
\end{aligned} sin 2 θ + cos 2 θ 1 + tan 2 θ 1 + cot 2 θ = 1 = sec 2 θ = csc 2 θ
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 \\
2 x - y + 3 z & = 0 \\
x - 2 y - 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 + 2 x + 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 Piecewise function:
f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\
-x^2 & \text{if } x < 0
\end{cases} \tag{5} Sign function:
\text{sgn}(x) = \begin{cases}
1 & \text{if } x > 0 \\
0 & \text{if } x = 0 \\
-1 & \text{if } x < 0
\end{cases} \tag{6}
Gathered and Centered Equations
% Multiple centered lines with one number
\begin { equation }
\begin { gathered }
(a + b)^ 2 = a^ 2 + 2 ab + b^ 2 \\
(a - b)^ 2 = a^ 2 - 2 ab + 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 + 2 x + 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 }
2 x + 3 & = 7 & & \text{(given)} \\
2 x & = 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 - 4 ac}}{ 2 a} $ }
\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 + 2 x}_{\text{quadratic}} +
\overbrace{ 3 x + 4 }^{\text{linear}}
\end { equation }
Equation Spacing
Manual Spacing in Equations
% Spacing commands
\begin { align }
f(x) & = x^ 2 + 2 x+ 1 \\ % No space
f(x) & = x^ 2 + 2 x + 1 \\ % Normal space
f(x) & = x^ 2 \, + \, 2 x \, + \, 1 \\ % Thin space
f(x) & = x^ 2 \: + \: 2 x \: + \: 1 \\ % Medium space
f(x) & = x^ 2 \; + \; 2 x \; + \; 1 \\ % Thick space
f(x) & = x^ 2 \quad+\quad 2 x\quad+\quad 1 % 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}
2 x & + & 3 y & - & z & = & 4 \\
x & - & y & + & 2 z & = & 1 \\
3 x & + & y & - & z & = & 0
\end { array }
\right.
\end { equation }
% Using aligned
\begin { equation }
\left\{
\begin { aligned }
2 x + 3 y - z & = 4 \\
x - y + 2 z & = 1 \\
3 x + y - z & = 0
\end { aligned }
\right.
\end { equation }
Rendered output \left\{
\begin{aligned}
2x + 3y - z &= 4 \\
x - y + 2z &= 1 \\
3x + y - z &= 0
\end{aligned}
\right. \tag{7}
Derivations
\begin { align }
(x + y)^ 2 & = (x + y)(x + y) \\
& = x(x + y) + y(x + y) \\
& = x^ 2 + xy + yx + y^ 2 \\
& = x^ 2 + 2 xy + y^ 2
\end { align }
Rendered output ( x + y ) 2 = ( x + y ) ( x + y ) = x ( x + y ) + y ( x + y ) = x 2 + x y + y x + y 2 = x 2 + 2 x y + y 2 \begin{aligned}
(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{aligned} ( x + y ) 2 = ( x + y ) ( x + y ) = x ( x + y ) + y ( x + y ) = x 2 + x y + y x + y 2 = x 2 + 2 x y + y 2
Quick Reference
Environment Purpose Numbering equationSingle equation Yes equation*Single equation No alignMultiple aligned equations Yes (each) align*Multiple aligned equations No splitSplit long equation One number multlineVery long equation One number gatherCentered equations Yes (each) casesPiecewise functions Within equation