Fraction in LaTeX
Updated:
A fraction is written as \frac{numerator}{denominator}. Inside a sentence LaTeX shrinks the fraction so it does not stretch the line; when you want full height, use \dfrac from the amsmath package.
Try it with your own values
Edit the code and the preview updates as you type.
\frac{a}{b}Always wrap the numerator and denominator in braces, even when they are a single letter. The code stays correct when you later add more characters to either part.
Copying this from handwritten notes? Snap a photo of the page and CamteX turns the formulas into LaTeX. Try it free
$\dfrac{1}{2} mv^2$In running text \frac shrinks the fraction to the height of the line. \dfrac forces display size; use it sparingly, because it pushes the surrounding lines of the paragraph apart.
\frac{1}{1 + \frac{1}{x}}LaTeX sets the inner fraction in a smaller size so the whole thing does not get too tall. One level looks fine; for deeper nesting reach for \cfrac.
\cfrac{1}{1 + \cfrac{1}{1 + \cfrac{1}{x}}}\cfrac from amsmath keeps every level at full size. Plain \frac in this role makes each level smaller than the last until it becomes unreadable.
\left( \frac{a}{b} \right)^2Plain ( ) stay short next to a tall fraction. \left and \right size them to the content, and they work the same way with square brackets and braces.
\binom{n}{k} = \frac{n!}{k!\,(n-k)!}A binomial coefficient looks like a fraction without the bar, but it has its own command, \binom, from amsmath. The \, is a thin space that separates the factorials in the denominator.
x^{1/2}In an exponent or subscript a stacked fraction would be too small to read, so a plain slash is used instead. The same goes for fractions in the middle of a sentence, such as a speed s/t.
\frac{1}{2} \quad \dfrac{1}{2} \quad \tfrac{1}{2}In display math \frac and \dfrac look the same; in a sentence \frac and \tfrac do. Use \tfrac for a small coefficient such as 1/2 in front of a large displayed expression.
\begin{pmatrix} \dfrac{1}{2} & 0 \\ 0 & \dfrac{3}{4} \end{pmatrix}Matrix cells and cases rows are set at text size, so \frac comes out small there. \dfrac restores full size; for a whole cases block, dcases from mathtools does the same.
\frac{\dfrac{a}{b} + 1}{\dfrac{c}{d} - 1}Inside a fraction LaTeX shrinks the inner ones a step. \dfrac keeps them at full size, which reads better when both the numerator and the denominator hold a fraction.
\sfrac{3}{4}\sfrac sets a raised numerator, a slash and a lowered denominator, as in 3/4 of a sample. It needs \usepackage{xfrac}, also works in running text, and KaTeX does not render it.
(a+b)^n = \sum_{k=0}^{n} \binom{n}{k} a^{n-k} b^{k}\binom follows the same size rules as \frac. In running text \tbinom keeps the coefficient small and \dbinom forces display size, just like \tfrac and \dfrac.
Common mistakes and fixes
| Wrong | Right | Why |
|---|---|---|
{n \choose k} | \binom{n}{k} | \choose is plain TeX syntax that amsmath flags with a Foreign command warning; \binom gives the same output. |
1/2x | \frac{1}{2}x | 1/2x is ambiguous: many readers take it as 1/(2x). A stacked fraction shows which part is the denominator. |
\frac(x+1)(x-1) | \frac{x+1}{x-1} | \frac takes its arguments in braces; with round brackets the first two characters, ( and x, become the numerator and denominator. |
- Missing braces: \frac12 works for single digits, but \frac 10 2 does not.
- Using \dfrac in a superscript, where the fraction becomes too large. Write a/b there instead.
- A slash in display math: a/b+c is ambiguous, while \frac{a}{b+c} shows at a glance what belongs in the denominator.
- {a \over b} from plain TeX: it works, but amsmath warns with Foreign command \over. Use \frac.
See also
- Square root in LaTeX
- Superscript and subscript in LaTeX
- Brackets in LaTeX
- Integral in LaTeX
- Sum and product in LaTeX
- Limit in LaTeX
Don't want to memorize commands?
Draw a formula or paste a screenshot, and CamteX turns it into ready LaTeX.