How to Write a Fraction in LaTeX

Write a fraction in LaTeX with \frac{numerator}{denominator} in math mode, for example $\frac{1}{2}$. Use \dfrac to force a full-size fraction in a line of text, \tfrac for a small one, and plain a/b when a slash reads better.

Fraction commands

  • \frac{a}{b}
    a b

    Standard fraction; size follows the context.

  • \dfrac{a}{b}
    a b

    Display-size fraction, even inline (amsmath).

  • \tfrac{a}{b}
    a b

    Text-size (small) fraction, even in a display (amsmath).

  • a/b
    a / b

    Slash form; good for inline math and exponents.

  • \cfrac{1}{1 + \cfrac{1}{x}}
    1 1 + 1 x

    Continued fraction with full-size levels (amsmath).

  • \frac{\partial f}{\partial x}
    ∂ f ∂ x

    Derivatives are fractions too.

  • \sfrac{1}{2}
    Text mode, no math preview

    Slanted fraction ½ style — \usepackage{xfrac}.

  • \nicefrac{1}{2}
    Text mode, no math preview

    Slanted fraction — \usepackage{nicefrac} (or units).

  • \genfrac{}{}{0pt}{}{a}{b}
    a b

    Stack without a fraction bar.

Try it live

Change the formula and the preview redraws as you type. Copy the LaTeX, download a PNG or SVG, copy it for Word, or use Edit here on any example below to load it.

Templates

Fractions examples

Each result below is drawn from the LaTeX under it. Copy the code, edit it on this page, or open it in the full editor.

  • Quadratic formula

    x = − b ± b 2 − 4 a c 2 a
    LaTeX
    x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
  • Nested fraction

    1 x + 1 y x + y = 1 x y
    LaTeX
    \frac{\frac{1}{x} + \frac{1}{y}}{x + y} = \frac{1}{xy}
  • Continued fraction

    2 = 1 + 1 2 + 1 2 + 1 2 + ⋯
    LaTeX
    \sqrt{2} = 1 + \cfrac{1}{2 + \cfrac{1}{2 + \cfrac{1}{2 + \cdots}}}
  • Fraction in parentheses

    ( a b ) 2 = a 2 b 2
    LaTeX
    \left( \frac{a}{b} \right)^2 = \frac{a^2}{b^2}

    \left( … \right) grows the parentheses to the height of the fraction.

  • Inline size vs display size

    1 2 vs 1 2
    LaTeX
    \tfrac{1}{2} \quad \text{vs} \quad \dfrac{1}{2}
  • Slash in an exponent

    x 1 / 2 = x
    LaTeX
    x^{1/2} = \sqrt{x}

    A stacked fraction in an exponent is hard to read; the slash is the usual style.

  • Fraction in a sum

    ∑ n = 1 ∞ 1 2 n = 1
    LaTeX
    \sum_{n=1}^{\infty} \frac{1}{2^n} = 1

How to write a fraction

Inside math mode type \frac, then the numerator and denominator each in braces: \frac{x+1}{x-1}. The braces are required whenever a part has more than one character; \frac12 works for single digits but is harder to read.

Fractions nest freely: \frac{1}{\frac{1}{a} + \frac{1}{b}}. Nested fractions shrink one size per level, so for continued fractions use \cfrac, which keeps every level full size.

Fraction size: \frac, \dfrac and \tfrac

\frac adapts: full size in displayed equations, smaller in a line of text and in subscripts. \dfrac forces the display size — useful in cases or tables — but inline it pushes the lines apart. \tfrac forces the small size.

For inline text, a slash ($a/b$) or a slanted fraction from xfrac (\sfrac{1}{2}) keeps the line spacing even.

Common mistakes

  • Without braces \frac takes only the next single character as each argument.

    Instead of
    \frac a+b c
    Write
    \frac{a+b}{c}
  • Typed parentheses stay one line tall and look too small around a fraction.

    Instead of
    (\frac{a}{b})^2
    Write
    \left( \frac{a}{b} \right)^2
  • \over is a plain-TeX primitive; it works but clashes with amsmath and is hard to read. Use \frac.

    Instead of
    {a \over b}
    Write
    \frac{a}{b}
  • Outside math mode \frac is an error. For a text fraction use xfrac's \sfrac or a slash.

    Instead of
    1/2 cup  (in text, as a math fraction)
    Write
    \sfrac{1}{2} cup

In Overleaf, MathJax and Word

  • Overleaf and pdfLaTeX

    \frac is built in; \dfrac, \tfrac, \cfrac and \genfrac need amsmath; \sfrac needs xfrac and \nicefrac needs nicefrac.

  • MathJax and KaTeX

    MathJax and KaTeX support \frac, \dfrac, \tfrac, \cfrac and \genfrac, but not \sfrac or \nicefrac. In Markdown apps put the fraction between $ … $.

  • Microsoft Word

    In a Word equation, typing a/b followed by a space turns it into a stacked fraction. To paste a LaTeX fraction as an editable Word equation, use Copy for Word in the editor above.

Fractions in LaTeX: questions

How do I write a fraction in LaTeX?
Use \frac{numerator}{denominator} in math mode, e.g. $\frac{3}{4}$.
How do I make a fraction bigger in a line of text?
Use \dfrac{a}{b} (amsmath) to force the display size. It makes the line taller, so a slash a/b often reads better inline.
How do I write a fraction without the line?
Use \genfrac{}{}{0pt}{}{a}{b}, or \binom{a}{b} if you want a binomial coefficient with parentheses.
How do I write 2/3 as a diagonal fraction?
In a document, load xfrac and write \sfrac{2}{3}. In MathJax, write 2/3 or {}^{2}/_{3}.
Can I get the LaTeX of a fraction from a screenshot?
Yes. Paste the screenshot into the image to LaTeX converter on the home page; it returns \frac code with a preview to check.

Have the formula as a picture?

Paste a screenshot or photo of the equation and get its LaTeX, ready to copy or open in the editor.

Convert an image to LaTeX