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}Standard fraction; size follows the context.
\dfrac{a}{b}Display-size fraction, even inline (amsmath).
\tfrac{a}{b}Text-size (small) fraction, even in a display (amsmath).
a/bSlash form; good for inline math and exponents.
\cfrac{1}{1 + \cfrac{1}{x}}Continued fraction with full-size levels (amsmath).
\frac{\partial f}{\partial x}Derivatives are fractions too.
- Text mode, no math preview
\sfrac{1}{2}Slanted fraction ½ style —
\usepackage{xfrac}. - Text mode, no math preview
\nicefrac{1}{2}Slanted fraction —
\usepackage{nicefrac}(or units). \genfrac{}{}{0pt}{}{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.
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
LaTeXx = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}Nested fraction
LaTeX\frac{\frac{1}{x} + \frac{1}{y}}{x + y} = \frac{1}{xy}Continued fraction
LaTeX\sqrt{2} = 1 + \cfrac{1}{2 + \cfrac{1}{2 + \cfrac{1}{2 + \cdots}}}Fraction in parentheses
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
LaTeX\tfrac{1}{2} \quad \text{vs} \quad \dfrac{1}{2}Slash in an exponent
LaTeXx^{1/2} = \sqrt{x}A stacked fraction in an exponent is hard to read; the slash is the usual style.
Fraction in a sum
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
\fractakes only the next single character as each argument.Instead of\frac a+b cWrite\frac{a+b}{c}Typed parentheses stay one line tall and look too small around a fraction.
Instead of(\frac{a}{b})^2Write\left( \frac{a}{b} \right)^2\overis 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
\fracis an error. For a text fraction use xfrac's\sfracor a slash.Instead of1/2 cup (in text, as a math fraction)Write\sfrac{1}{2} cup
In Overleaf, MathJax and Word
Overleaf and pdfLaTeX
\fracis built in;\dfrac,\tfrac,\cfracand\genfracneed amsmath;\sfracneeds xfrac and\nicefracneeds nicefrac.MathJax and KaTeX
MathJax and KaTeX support
\frac,\dfrac,\tfrac,\cfracand\genfrac, but not\sfracor\nicefrac. In Markdown apps put the fraction between$ … $.Microsoft Word
In a Word equation, typing
a/bfollowed 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 slasha/boften 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, write2/3or{}^{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
\fraccode with a preview to check.
Related LaTeX reference
- Square Root in LaTeX\sqrt{x} for square roots, \sqrt[n]{x} for cube and nth roots, nested radicals, and \vphantom to even out root heights.
- Binomial Coefficients (Choose) in LaTeX\binom{n}{k} for n choose k, the older {n \choose k}, \dbinom and \tbinom sizes, and multinomial and combination notation.
- Derivative in LaTeXdy/dx with \frac, f'(x) and f''(x), nth derivatives, \dot and \ddot for time derivatives, and what to do about \dv.
- LaTeX equation editorSymbol panel, live preview, and PNG, SVG, MathML or Word export.
- All LaTeX reference pagesSymbols, math structures and text formatting in one list.
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