Formatting Fractions
Fractions come in two varieties: Display style and text style. A text style fraction is small enough to fit within the height of a line of text, like $\frac{a}{b}$. In contrast, a display style fraction is taller and will extend beyond the normal line height if used in text: $\dfrac{a}{b}$. A text style fraction is used automatically by LaTeX in the following circumstances:
- In inline equations delimited by
$ ... $
or $( … )$, such as$\frac{a}{b}$
($\frac{a}{b}$). - In the numerator or denominator of another fraction.
- In matrix environments, such as
pmatrix
orbmatrix
. - In
cases
environments.
Here is a example that demonstrates text style fractions:
Code:
$$
\frac{1 + \frac{1}{2}}{2}
+
\begin{bmatrix}
1 & \frac{1}{2} & \frac{1}{3}
\end{bmatrix}
+
\begin{cases}
2 + \frac{1}{4} \\
\frac{1}{5}
\end{cases}.
$$
\[ \frac{1 + \frac{1}{2}}{2} + \begin{bmatrix} 1 & \frac{1}{2} & \frac{1}{3} \end{bmatrix} + \begin{cases} 2 + \frac{1}{4} \\ \frac{1}{5} \end{cases} \]Output:
In contrast, a display style fraction is used in the following cases:
- In a display equation, delimited by
\[...\]
,$$...$$
,\begin{equation} \end{equation}
or the other similar environments (equation*
,align
, andalign*
). - Anywhere (including where a text style fraction would normally be used) if
\dfrac
is used instead of\frac
, or if\displaystyle
is placed anywhere before the fraction.
When writing a fraction in LaTeX, consider the following guidelines:
- Do not use display style fractions inline, in text. They will look bad and cause the height of the lines to grow.
- Only use text style fractions for simple fractions, such as $\frac{1}{2}$. Do you want to read a fraction like $\frac{1+\sqrt{x^2}}{e^{-\frac{x}{\pi}}}$? I wouldn’t! Either make the equation a display equation (e.g., if it is in a
bmatrix
environment where there is sufficient space), or rewrite the equation with a slash, like $(1+\sqrt{x^2})/(e^{-x/\pi})$. - If writing a fraction using the slash notation and the expression for the numerator or denominator is taller than a typical line of text, use
\left. <numerator> \middle/ <denominator>\right
to ensure that the slash matches the height of the numerator and denominator. The
\shortfrac
macro provxided here automatically scales the slash for you. - When a minus sign occurs before a fraction, it more easily lost in calculations, so consider rewriting the expression. For instance, rewrite “$-\frac{a}{b}$” into “\frac{-a}{b}”. If possible, eliminate the minus sign by distributing it to the numerator or denominator, such as “$-\frac{a - b}{c}$” changing to “$\frac{b - a}{c}$.”
- When practical, avoid placing fractions inside fractions. For instance, change \(\frac{1 + 1/n}{1} \quad \text{into} \quad \frac{n + 1}{n}.\)