To write a LaTeX fraction, use \frac{numerator}{denominator} inside maths mode, for example $\frac{1}{2}$. Inline, LaTeX sets fractions small so they fit the line; in a displayed equation they are full size. To control the size yourself, load amsmath and use \dfrac (always large) or \tfrac (always small). This guide covers those three commands, plus continued fractions with \cfrac, slanted fractions like ½, binomial coefficients, brackets around fractions, and the two errors beginners hit most.
Every example on this page was compiled with Tectonic 0.17 (a self-contained TeX engine based on XeTeX) on 2 December 2026, and the error messages are copied from the real build logs. The code is standard LaTeX and works the same way in Overleaf. New to LaTeX? Start with our beginner’s LaTeX tutorial.
TL;DR: LaTeX Fraction Commands
| You want | Use | Package |
|---|---|---|
| A normal fraction | \frac{a}{b} | None |
| A large fraction inside a paragraph | \dfrac{a}{b} | amsmath |
| A small fraction inside a displayed equation | \tfrac{a}{b} | amsmath |
| A continued fraction | \cfrac{1}{2 + \cfrac{1}{3}} | amsmath |
| A slanted fraction like ½ in running text | \sfrac{1}{2} | xfrac |
| A plain slash | a/b | None |
| A binomial coefficient | \binom{n}{k} | amsmath |
| Brackets that fit the fraction | \left( \frac{a}{b} \right) | None |

How to Write a Fraction in LaTeX With \frac
\frac takes two arguments in braces: the numerator first, then the denominator. It only works in maths mode, so wrap it in $...$ for inline maths or \[...\] for a displayed equation. You don’t need any package for it.
\documentclass{article}
\begin{document}
Half of the budget is $\frac{1}{2}$ and the ratio is $\frac{a+b}{c-d}$.
A display fraction is larger:
\[
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\]
\end{document}In the compiled PDF, the inline ½ and (a+b)/(c−d) were set small so the line spacing stayed even, while the quadratic formula in the display was set at full size. That automatic sizing is the main thing to understand about LaTeX fractions: \frac adapts to where it is used.
Anything can go in the numerator or denominator, including square roots, powers and other fractions. Keep the braces even for single characters. \frac12 does compile and gives the same ½ (we checked), because TeX takes the next single token as each argument, but \frac1{10}-style shortcuts get hard to read and break as soon as an argument has two characters:
\documentclass{article}
\begin{document}
$\frac12$ and $\frac{1}{2}$ give the same output. $\frac1{10}$ works too.
\end{document}dfrac vs tfrac: Control the Fraction Size
The amsmath package adds two variants of \frac that ignore the surrounding context:
\dfrac(display fraction) is always full size, even inside a paragraph.\tfrac(text fraction) is always small, even inside a displayed equation.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Inline: $\frac{1}{2}$ versus $\dfrac{1}{2}$.
Display:
\[
\frac{1}{2} \quad \tfrac{1}{2} \quad \dfrac{1}{2}
\]
\end{document}In the output, the inline \dfrac{1}{2} was as tall as a display fraction and pushed the lines apart, and the displayed \tfrac{1}{2} was as small as an inline one. Use \dfrac sparingly in paragraphs: it makes uneven line spacing. A good use is a short formula that must stay readable, such as a rate in a table cell. If you need fractions in tables, our LaTeX tables guide covers the table side.
You can get the same effect without amsmath by putting \displaystyle or \textstyle in front of \frac, but \dfrac and \tfrac are shorter and only affect the one fraction.
Continued and Nested Fractions With \cfrac
If you nest \frac inside \frac, each level gets smaller. By the third level the digits are tiny. amsmath’s \cfrac keeps every level at full size, which is how continued fractions are normally typeset:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Nested with \verb|\frac| (shrinks):
\[
x = 1 + \frac{1}{2 + \frac{1}{3 + \frac{1}{4}}}
\]
With \verb|\cfrac| (stays readable):
\[
x = 1 + \cfrac{1}{2 + \cfrac{1}{3 + \cfrac{1}{4}}}
\]
Left-aligned numerator:
\[
\cfrac[l]{1}{2 + x}
\]
\end{document}The first equation shrank to script size at the third level; the \cfrac version kept all four digits the same size. The optional argument [l] or [r] moves the numerator to the left or right instead of centring it.
Slanted and Slash Fractions in Running Text
In body text (a recipe, a ratio in a sentence) a stacked fraction often looks out of place. You have three options. Write a plain slash: $a/b$. Use the ready-made text symbols \textonehalf and \textonequarter for common fractions. Or load the xfrac package on CTAN and use \sfrac for any split-level fraction like ½:
\documentclass{article}
\usepackage{lmodern}
\usepackage{xfrac}
\begin{document}
Slash: $a/b$ and $(x+1)/(x-1)$.
Split-level with xfrac: \sfrac{1}{2} cup of flour, and $\sfrac{3}{4}$ in maths.
\end{document}\sfrac works in both text and maths mode. One thing we hit while testing: with the default Computer Modern fonts, xfrac printed LaTeX Font Warning: Size substitutions with differences up to 3.25pt have occurred. It asks for very small font sizes that the default Computer Modern set doesn’t include, so LaTeX swaps in the nearest size it has. Adding \usepackage{lmodern} before xfrac (as above) removed every warning, since Latin Modern is scalable to any size.
\documentclass{article}
\begin{document}
Use \textonehalf{} or \textonequarter{} for common text fractions, or write 1/2.
\end{document}This printed “Use ½ or ¼ for common text fractions”. These commands need no package, and they are the simplest option when you only need a few common fractions in prose.
Binomial Coefficients and Other Fraction-Like Notation
A binomial coefficient looks like a fraction without the bar. Use amsmath’s \binom, and \dbinom or \tbinom to force the size, exactly like \dfrac and \tfrac:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Inline $\binom{n}{k}$, forced large $\dbinom{n}{k}$.
\[
\binom{n}{k} = \frac{n!}{k!\,(n-k)!}
\]
\end{document}For anything else, \genfrac is the general command behind all of these. Its six arguments are: left delimiter, right delimiter, bar thickness (empty for normal, 0pt for no bar), style (0 to 3, from display to scriptscript; empty for automatic), numerator and denominator. Derivatives are just ordinary fractions:
\documentclass{article}
\usepackage{amsmath}
\newcommand{\half}{\genfrac{}{}{}{1}{1}{2}}
\begin{document}
Custom: $\genfrac{[}{]}{0pt}{}{n}{k}$ and $\half$.
\[
\frac{\partial f}{\partial x} \qquad \frac{dy}{dx} \qquad \frac{\mathrm{d}y}{\mathrm{d}x}
\]
\end{document}For the operator and Greek-letter symbols used inside these formulas (∂, ±, √), see our LaTeX symbols cheat sheet.
Brackets Around Fractions: \left and \right
Ordinary parentheses keep their normal height, so they look too short around a displayed fraction. Put \left and \right in front of the brackets to make LaTeX scale them, or use \big, \Big, \bigg or \Bigg for a fixed size:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Too small:
\[
(\frac{a}{b})^2
\]
Scaled with \verb|\left| and \verb|\right|:
\[
\left(\frac{a}{b}\right)^2
\]
Fixed size with \verb|\bigg|:
\[
\bigg(\frac{a}{b}\bigg)^2
\]
\end{document}In the output, the first pair of parentheses only reached the middle of the fraction; the \left( ... \right) pair covered the full height. Every \left needs a matching \right in the same formula; use \right. (with a dot) if you want no bracket on that side.
Avoid \over in LaTeX Documents
You will see {a \over b} in old code and on Q&A sites. It is the plain TeX syntax. It still compiles, but with amsmath loaded we got this warning in the log:
Package amsmath Warning: Foreign command \over;
(amsmath) \frac or \genfrac should be used instead
(amsmath) on input line 4.\documentclass{article}
\usepackage{amsmath}
\begin{document}
$a \over b$
\end{document}\over takes everything before it in the current group as the numerator, which makes errors easy and code hard to read. Use \frac.
Common LaTeX Fraction Errors
These are the two errors we reproduced. Both come up again and again in beginner documents.
Undefined control sequence (\dfrac without amsmath)
\documentclass{article}
\begin{document}
$\dfrac{1}{2}$
\end{document}Tectonic stopped with ! Undefined control sequence. pointing at l.3 $\dfrac. \dfrac, \tfrac, \cfrac and \binom all come from amsmath. Fix: add \usepackage{amsmath} to the preamble. Overleaf’s default templates already load it, which is why the same code may work there and fail in a minimal local file.
Missing $ inserted (fraction outside maths mode)
\documentclass{article}
\begin{document}
Add \frac{1}{2} cup of sugar.
\end{document}This gave ! Missing $ inserted. at l.3 Add \frac{1}{2}. \frac is a maths command, so LaTeX refuses it in plain text. Fix: write $\frac{1}{2}$, or use \sfrac{1}{2} or \textonehalf for a fraction inside a sentence.
The full list of maths-mode rules is in the LaTeX2e reference on math formulas. If a fraction looks too big or small next to its text, check the surrounding font size first; our LaTeX font size guide explains how size commands interact with maths.
Conclusion
For almost every LaTeX fraction, \frac{a}{b} is all you need: it sizes itself for inline or display maths. Load amsmath for \dfrac, \tfrac, \cfrac and \binom, use \left( \right) for brackets that fit, and switch to a slash, \textonehalf or \sfrac when a fraction sits inside a sentence. If you write in Overleaf, our Overleaf guide shows where to put these packages in a project.
How do you write a fraction in LaTeX?
Use \frac{numerator}{denominator} inside maths mode, for example $\frac{3}{4}$ inline or \[ \frac{3}{4} \] on its own line. No package is needed.
What is the difference between frac, dfrac and tfrac?
\frac changes size with the context: small inline, large in a displayed equation. \dfrac is always large and \tfrac is always small. \dfrac and \tfrac need the amsmath package.
Why do I get Undefined control sequence for dfrac?
\dfrac comes from amsmath. Add \usepackage{amsmath} to the preamble and the error goes away. The same applies to \tfrac, \cfrac and \binom.
How do I write a fraction like ½ in normal text?
Use \textonehalf or \textonequarter for common fractions, a plain slash such as 1/2, or load the xfrac package and write \sfrac{1}{2}. A stacked \frac outside maths mode causes a Missing $ inserted error.
How do I make brackets fit around a fraction?
Write \left( \frac{a}{b} \right). LaTeX then scales the brackets to the height of the fraction. For a fixed size use \big, \Big, \bigg or \Bigg before each bracket.
How do I write a continued fraction in LaTeX?
Use \cfrac from amsmath, for example 1 + \cfrac{1}{2 + \cfrac{1}{3}}. Unlike nested \frac, every level stays the same size.







