LaTeX Fraction: frac, dfrac, tfrac and Nested Fractions
November 11, 2026 · 9 min read
LaTeX Fraction Syntax: \frac, \dfrac, \tfrac and Nested Fractions
A LaTeX fraction is written with \frac{numerator}{denominator} inside math mode, so \frac{2}{3} stacks 2 over 3 with a bar between them. Swap in \dfrac for a full-size fraction, \tfrac for a small one, or \cfrac for continued fractions. This page shows each form, the size you get, and which ones work in Markdown.
How Do You Write a Fraction in LaTeX?
Type \frac, then the numerator in one pair of braces and the denominator in a second pair. The command is part of core LaTeX, so it needs no package, and it renders in KaTeX and MathJax too. It only works in math mode: outside it, compiled LaTeX stops with a "Missing $ inserted" error. In Markdown you wrap it in math delimiters; our guide to Markdown equations covers those and where they render.
Half the batch is $\frac{1}{2}$ of the total.
$$
\frac{x + 1}{x - 1}
$$
In the first line, the half renders small enough to fit the line height. The display block puts the second fraction on its own line, centered and at full size.
Single digits can skip the braces: \frac12 gives because each digit is one token. That shortcut breaks fast, though. \frac123 renders as , a half followed by a loose 3. We prefer typing the braces every time, even for one digit, so edits never change the meaning.
So frac in LaTeX is one command with two arguments, and most fractions need nothing more.
You'll also meet {a \over b} in older plain TeX code. KaTeX renders it, but with amsmath loaded, compiled LaTeX prints a warning that suggests \frac or \genfrac instead. Stick with \frac.
One mistake turns up in a lot of student work: \frac{a,b}. LaTeX reads a,b as the numerator and grabs whatever comes next as the denominator, so you get an error or a wrong result. A fraction in LaTeX needs two separate brace groups: \frac{a}{b}.
LaTeX Fraction Sizes: \frac vs \dfrac vs \tfrac
A plain \frac changes size depending on where it sits, which surprises a lot of people new to fractions in LaTeX. Inside inline math it uses text style, which is small. Inside display math it uses display style, which is large. The \dfrac and \tfrac commands lock the size so it stops changing. The amsmath user's guide defines them as shortcuts for \displaystyle\frac and \textstyle\frac.
| Command | Inline math | Display math | LaTeX package | In KaTeX |
|---|---|---|---|---|
\frac{a}{b} | Small, | Full size | None (core) | Yes |
\dfrac{a}{b} | Full size, | Full size | amsmath | Yes |
\tfrac{a}{b} | Small, | Small | amsmath | Yes |
\cfrac{a}{b} | Full size | Full size, built for continued fractions | amsmath | Yes, but not the [l] or [r] option |
a/b | Same size as the text, | Same size as the text | None | Yes |
\sfrac{a}{b} | Small and slashed | Small and slashed | xfrac | No |
\nicefrac{a}{b} | Small and slashed | Small and slashed | nicefrac | No |
Two rows in that table cause most of the confusion. A \dfrac in a paragraph pushes the lines apart, because it's as tall as a display equation. And \tfrac in a display block looks oddly small next to full-size symbols.
The general switches are \displaystyle and \textstyle. Put one at the start of an expression and every fraction after it follows that style.
How Do You Write 2/3 in LaTeX?
You have four reasonable ways to write two thirds. Each renders as a different shape, so pick by context.
$\frac{2}{3}$ $\tfrac{2}{3}$ $\dfrac{2}{3}$ $2/3$
Those render as , , and . In running text, \frac{2}{3} and \tfrac{2}{3} give the same small result, and the slash keeps line spacing even. Use \dfrac{2}{3} only in a display block or a table cell where height doesn't matter.
For a recipe or a measurement, the slash usually reads best. For an equation the reader has to work through, the stacked form is clearer. For a mixed number, put the whole part right before the fraction: $2\tfrac{1}{3}$ gives .
Nested Fractions Without Tiny Numbers
Put a fraction inside another one and the inner parts shrink. In display math, the numerator and denominator of a \frac are set in text style. So an inner \frac drops a size, and its own numbers fall to script size.
$$
\frac{\frac{a}{b}}{\frac{c}{d}} \qquad \frac{\dfrac{a}{b}}{\dfrac{c}{d}}
$$
That renders as:
The left version squeezes , , and into small type. The right version uses \dfrac for the inner parts, so every letter stays readable. That's the standard fix for a nested LaTeX fraction: make the inner ones \dfrac.
Deep nesting has a limit, though. Past two levels, no command makes a stack of fractions easy to read, so rewrite it. A compound fraction like \frac{a/b}{c/d} or a product such as \frac{a}{b} \cdot \frac{d}{c} often says the same thing in less height. The \cdot dot and the \div sign are in our LaTeX symbols list.
Continued Fractions with \cfrac
A continued fraction repeats the nesting many times, which is exactly where \frac falls apart. The amsmath \cfrac command keeps every level at full display size, so the deepest terms stay as readable as the first.
$$
x = 1 + \cfrac{1}{2 + \cfrac{1}{3 + \cfrac{1}{4}}}
$$
That renders as:
Try the same expression with \frac and each level gets smaller until the deepest terms sit at the smallest script size.
In compiled LaTeX, \cfrac[l] and \cfrac[r] push a numerator to the left or right, as the amsmath guide describes. KaTeX doesn't document that option, and it doesn't raise an error either. In our test with KaTeX 0.16.28, \cfrac[l]{1}{2} read the bracket and the letter as a fraction, then printed the rest as stray text. Leave the option out wherever KaTeX renders your Markdown. Our KaTeX vs LaTeX guide lists other LaTeX features KaTeX doesn't support.
How Do You Make 1/2 Small in Text?
In a paragraph, you often want a compact half that doesn't disturb the line height. In compiled LaTeX, two common packages give you a slashed fraction. xfrac provides \sfrac{1}{2}, which raises a small 1, adds a slash and lowers a small 2. The older nicefrac package provides \nicefrac{1}{2} with a similar result.
Neither works in KaTeX. The KaTeX list of supported functions doesn't include them, and KaTeX stops with an "Undefined control sequence" error for both. If a document depends on packages like these, that's a good sign it belongs in compiled LaTeX; our Markdown vs LaTeX comparison covers that choice.
For a LaTeX fraction slash that KaTeX accepts, use one of these:
$\tfrac{1}{2}$ $1/2$ ${}^{1}\!/_{2}$
Those render as , and . The third one builds the slashed look by hand: an empty group carries a superscript 1, then a slash, then a subscript 2. It works in KaTeX and in compiled LaTeX. Our LaTeX subscript and superscript guide explains the empty-group trick.
Unicode also has ready-made characters such as ½ (U+00BD), but they're plain text rather than LaTeX, and only a handful of fractions exist.
Fractions in Parentheses and Fractions Without a Line
Brackets around a fraction should grow to fit it. A plain ( stays text height and looks cramped, so pair \left( with \right):
$$
\left( \frac{x+1}{x-1} \right)^2
$$
That renders as:
The parentheses stretch to cover the full height of the fraction.
To stack two values with no bar, use \binom{n}{k} when you want parentheses, or \genfrac{}{}{0pt}{}{n}{k} when you don't. They render as and . The \genfrac command takes six arguments: left delimiter, right delimiter, line thickness, style, numerator and denominator. Set the thickness to 0pt and the line disappears. For grids larger than two rows, a matrix fits better; see writing matrices in Markdown.
Test LaTeX Fractions in a Markdown Preview
The fastest way to learn how to make a fraction in LaTeX is to type a few and watch them render. The demo below holds the main forms from this page: the three sizes, the slashed trick, a nested pair, a continued fraction and a bracketed fraction. Edit any line and the preview updates.
For a single equation you want as an image, the LaTeX equation editor renders with KaTeX 0.16, has a symbol palette, and exports PNG or SVG. It can also copy the result as a Markdown math snippet.
A LaTeX fraction comes down to \frac with two brace groups, plus \dfrac or \tfrac when you need to fix the size and \cfrac for continued fractions. Skip \sfrac, \nicefrac and the \cfrac[l] option in KaTeX-rendered Markdown, since KaTeX can't handle them. Paste any example from this page into the editor and the split view shows it rendered on the right as you type.