Fractions and Binomials in LaTeX: \frac, \dfrac, \tfrac and \binom

Quick answer

  • Fraction: \frac{a}{b} in math mode.
  • Force the size: \dfrac{a}{b} (display) or \tfrac{a}{b} (inline), with amsmath.
  • Binomial: \binom{n}{k}, with amsmath.
  • No fraction line: \genfrac{}{}{0pt}{}{a}{b}.
  • In text: \sfrac{1}{2} with xfrac, or just 1/2.
\documentclass{article}
\usepackage{amsmath}
\begin{document}

Inline: $\frac{1}{2}$ and $\binom{n}{k}$.
\[
  \frac{x+1}{x-1} \qquad \binom{n}{k} = \frac{n!}{k!\,(n-k)!}
\]

\end{document}

A fraction in LaTeX is \frac{numerator}{denominator}, and that covers most of what you will write. The questions start when the fraction looks wrong: too small in a sentence, too big in a line of text, cramped when nested, or needed without a line at all. This guide covers the three fraction sizes, nested and continued fractions, binomial coefficients, \genfrac for custom fractions, and fractions in ordinary text, with a table of mistakes at the end. For worked formulas (quadratic formula, derivatives, partial fractions), see the fractions in LaTeX post on the blog. Every example compiles with pdfLaTeX.

\frac: The Basic Fraction

\frac takes two arguments in braces and works only in math mode. Either argument can contain any math:

\documentclass{article}
\begin{document}

The ratio $\frac{a}{b}$ sits in the line of text.
\[
  \frac{x^2 - 1}{x + 1} = x - 1
  \qquad
  \frac{\sqrt{a}}{2\pi}
  \qquad
  \frac{dy}{dx}
  \qquad
  \frac{\partial f}{\partial x}
\]

\end{document}

Braces can be dropped when each argument is a single character: \frac12 gives ½. That shortcut bites with longer numbers, because \frac123 means \frac{1}{2}3, so keep the braces in anything you share.

\frac vs \dfrac vs \tfrac

In a displayed equation, \frac sets both parts at full size. Inline, it shrinks them so the line spacing stays even. The amsmath commands \dfrac and \tfrac fix the size whatever the context:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

Inline: $\frac{1}{2}$, $\dfrac{1}{2}$ and $\tfrac{1}{2}$.
\[
  \frac{1}{2} \qquad \dfrac{1}{2} \qquad \tfrac{1}{2}
\]

\end{document}
CommandInline mathDisplay mathTypical use
\fracSmallFull sizeAlmost everything
\dfracFull sizeFull sizeFractions inside a matrix, cases or another fraction
\tfracSmallSmallA coefficient such as \tfrac12 x in a display

A full-size fraction inside a paragraph forces extra space between lines. For a sentence, $a/b$ often reads better than either size. The rules that decide these sizes are explained in display style in LaTeX.

Nested and Continued Fractions

Each level of nesting drops to a smaller style, so a fraction inside a fraction gets hard to read quickly. Use \dfrac for the inner parts, or \cfrac for continued fractions, which keeps every level full size and aligned:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\[
  \frac{1}{1 + \frac{1}{x}}
  \qquad
  \frac{1}{1 + \dfrac{1}{x}}
\]
\[
  \sqrt{2} = 1 + \cfrac{1}{2 + \cfrac{1}{2 + \cfrac{1}{2 + \dotsb}}}
\]
\[
  \left( \frac{a + b}{c} \right)^{2}
\]

\end{document}

\cfrac[l]{1}{x} and \cfrac[r]{1}{x} push the numerator left or right. Brackets that grow with the fraction come from \left and \right; see the brackets guide.

Binomial Coefficients: \binom

\binom{n}{k} from amsmath prints “n choose k” in parentheses with no line. It follows the same size rules as \frac, with \dbinom and \tbinom to force a size:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

There are $\binom{5}{2} = 10$ ways to choose 2 items from 5.
\[
  (x + y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{n-k} y^{k}
  \qquad
  \binom{n}{k} = \frac{n!}{k!\,(n-k)!}
\]

\end{document}

Plain TeX writes the same thing as {n \choose k}. It still prints, but it takes everything in the surrounding group as its arguments, and with amsmath loaded it logs a “Foreign command \atopwithdelims” warning; prefer \binom.

Fractions Without a Line: \genfrac

\genfrac is the general command behind \frac and \binom. Its six arguments are the left delimiter, the right delimiter, the rule thickness, the size (0 display, 1 text, 2 script, 3 scriptscript, empty for automatic), the numerator and the denominator:

\documentclass{article}
\usepackage{amsmath}
\newcommand{\stack}[2]{\genfrac{}{}{0pt}{}{#1}{#2}}
\begin{document}

\[
  \genfrac{}{}{0pt}{}{a}{b}        % no line
  \qquad
  \genfrac{[}{]}{0pt}{}{n}{k}     % Stirling-style brackets
  \qquad
  \genfrac{}{}{1pt}{0}{a}{b}      % thick line, display size
  \qquad
  \stack{i < n}{j < m}
\]
\[
  \sum_{\substack{0 \le i \le m \\ 0 < j < n}} P(i, j)
\]

\end{document}

The plain TeX {a \atop b} also stacks without a line, but with amsmath loaded it triggers a “Foreign command \atop” warning. For conditions under a sum, \substack is the clearer choice.

Fractions in Text: \sfrac, nicefrac and ½

\frac outside math mode is an error. In running text, choose between a slash, a slanted fraction from xfrac, or a ready-made symbol:

\documentclass{article}
\usepackage{xfrac}
\begin{document}

Add \sfrac{1}{2} cup of sugar and \sfrac{3}{4} cup of flour.

In math too: $\sfrac{a}{b}$, or a plain slash: $a/b$.

Ready-made symbols: \textonehalf, \textonequarter, \textthreequarters.

\end{document}

The older nicefrac package offers \nicefrac{1}{2} with a similar look. For units such as m/s, a slash or the siunitx package is more common than any fraction.

Common Mistakes

Message or symptomCauseFix
Missing $ inserted\frac or \binom outside math modeWrap it in $...$, or use \sfrac in text
Undefined control sequence on \dfrac, \tfrac or \binomamsmath not loaded\usepackage{amsmath}
\frac123 prints ½ followed by 3Braces dropped, so each argument is one character\frac{12}{3} or \frac{1}{23}
Tiny inner fraction in a nested fractionEach level drops one style\dfrac inside, or \cfrac
Uneven line spacing around an inline fraction\dfrac or a tall fraction in a paragraph\frac, \tfrac or a/b
Package amsmath Warning: Foreign command \overPlain TeX \over, \atop or \choose with amsmath\frac or \genfrac

Frequently Asked Questions

What is the difference between \frac, \dfrac and \tfrac?

\frac picks its size from the surroundings: small in inline math, full size in a display. \dfrac always uses the full display size and \tfrac always uses the small inline size. \dfrac and \tfrac come from the amsmath package.

How do I write a binomial coefficient (n choose k) in LaTeX?

Load amsmath and write \binom{n}{k}. Like \frac it adapts to inline or display math, and \dbinom and \tbinom force the display or inline size. The plain TeX form {n \choose k} also works but is not recommended in LaTeX documents.

How do I write a continued fraction in LaTeX?

Use \cfrac from amsmath and nest it: 1 + \cfrac{1}{2 + \cfrac{1}{2 + \dotsb}}. Unlike nested \frac, every level stays full size and the denominators line up. \cfrac[l] and \cfrac[r] set the numerator flush left or right.

Why does {n \choose k} give a warning in LaTeX?

\choose, \atop and \over are plain TeX commands. amsmath logs “Foreign command \atopwithdelims” (or \atop, \over) for them, and they take everything in the surrounding group as their arguments, which is easy to get wrong. Replace {n \choose k} with \binom{n}{k} and {a \over b} with \frac{a}{b}.

Why is a fraction inside another fraction so small?

Each level of a fraction drops one math style: in a display the parts of a fraction are set in text style, and a fraction inside them in script style. Write the inner one as \dfrac to keep it full size, or use \cfrac for continued fractions.

Next Steps

Free LaTeX Tools

Write math faster with AI

Describe a formula in words and Octree's AI writes the LaTeX, picks the right fraction size and fixes math-mode errors, with the PDF compiled next to your code.

Try Octree Free →