How to write a fraction in LaTeX
Use \frac{numerator}{denominator}in math mode. It is part of core LaTeX.
\documentclass{article}
\begin{document}
Inline: $\frac{1}{2}$.
Display:
\[
\frac{a + b}{c}
\]
\end{document}Both arguments need braces unless they are a single character. Inline, LaTeX shrinks the fraction to fit the line. In display math it draws it at full size.
The fraction commands
| Command | Package | Result |
|---|---|---|
| \frac{a}{b} | core | Size follows the context: small inline, full in display. |
| \dfrac{a}{b} | amsmath | Always display size. |
| \tfrac{a}{b} | amsmath | Always text (small) size. |
| \cfrac{a}{b} | amsmath | Continued fractions, full size at every level. |
| \binom{n}{k} | amsmath | Binomial coefficient, no bar. |
| a/b | core | Slashed, for inline use. |
Forcing the size
A tall fraction inside a sentence can push the lines apart. If you need it small in display math, or large in a sentence, use\tfrac or \dfrac. Both needamsmath.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Text size: $\tfrac{1}{2}$, display size: $\dfrac{1}{2}$.
\end{document}Nested fractions
Put one \frac inside another's argument. Inner fractions are set smaller each level, which gets hard to read after two.
\[
\frac{1 + \frac{1}{x}}{1 - \frac{1}{x}}
\]For a continued fraction, \cfrac keeps every level at full size.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
x = a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{a_3}}}
\]
\end{document}Slashed fractions in running text
Writing $a/b$ sets the slash on one line and keeps the line height even. This is the usual choice for a simple ratio or a unit such as m/s. Add parentheses when the numerator or denominator has more than one term: $(a+b)/c$. Thenicefrac package gives a diagonal fraction like ½ with \nicefrac{1}{2}.
Binomial coefficients
\binom{n}{k} draws n over k with no bar, in parentheses. It needs amsmath. Do not fake it with\frac.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\binom{n}{k} = \frac{n!}{k!\,(n-k)!}
\]
\end{document}Common mistakes
- Missing braces.
\frac12works, but\frac1/2takes1and/as its two arguments. Always brace anything beyond one character. - Old syntax.
{a \over b}still works but changes how the group around it behaves. Use\frac. - Undefined control sequence on
\dfrac.Loadamsmath. - Tiny inline fractions. If a fraction is hard to read in a sentence, use the slash form or
\dfrac. Do not shrink the text.
Templates that use this
Fractions are everywhere in problem sets and exams. Try themaths homework ormaths exam templates, or browse theassignment templates.
Related
Fractions often appear insidesums and integrals. To number and line up a chain of equations, seealigning equations. For a first document, read LaTeX for beginners, or start from an article template.