Learning how to do fractions in LaTeX is one of the first skills every student, researcher, and educator needs when typesetting mathematics. LaTeX makes it surprisingly easy to write clean, professional-looking fractions using the \frac command, and once you understand a few simple rules, you can handle everything from a basic one-half to complex nested fractions with square roots, variables, and exponents. This guide walks you through every step, complete with examples, common mistakes, and practical tips you can use right away.
The Basic Syntax: The \frac Command
The foundation of every fraction in LaTeX is the \frac command, which always takes two arguments:
\frac{numerator}{denominator}
The first set of curly braces holds the top part of the fraction, and the second set holds the bottom part. For example:
\frac{1}{2}
This produces a clean ½ with a horizontal fraction bar. In real terms, notice that both arguments are wrapped in curly braces {}, even when they contain only a single character. Skipping the braces is one of the most common beginner errors, and it will either break your document or produce unexpected output.
Here are a few more examples you can try immediately:
\frac{a}{b}produces a over b\frac{x+1}{x-1}puts the entire expression x + 1 on top and x − 1 below\frac{3}{4\pi}places 3 over 4π
Inline Mode vs. Display Mode
Where you place your fraction changes how it looks. LaTeX has two math modes, and understanding the difference is essential Turns out it matters..
Inline mode is used when the fraction appears inside a sentence, surrounded by single dollar signs:
The probability is $\frac{1}{6}$.
In inline mode, LaTeX automatically shrinks the fraction so it does not stretch the line height of your paragraph. This keeps your text compact, but very complex fractions can become hard to read.
Display mode places the fraction on its own line, centered, using double dollar signs or the \[ ... \] environment:
\[ \frac{1}{6} \]
In display mode, the fraction is rendered at full size, making it much easier to read. As a rule of thumb, use inline mode for simple fractions inside running text and display mode for important equations or complicated expressions No workaround needed..
Controlling Fraction Size: \dfrac and \tfrac
Sometimes you want more control over the size of your fraction. The amsmath package, which you should load in your preamble with \usepackage{amsmath}, gives you two powerful variants:
\dfracforces a display-style fraction, even inside inline math or nested expressions.\tfracforces a text-style (small) fraction, even in display mode.
Example:
Inline forced large: $\dfrac{1}{2}$
Display forced small: \[ \tfrac{1}{2} \]
These commands are especially useful when a small fraction is hiding inside a larger expression and you need it to stand out, or when a huge fraction is disrupting the flow of your paragraph.
Nested Fractions
A nested fraction is simply a fraction that contains another fraction in its numerator, denominator, or both. LaTeX handles them naturally:
\frac{1}{1 + \frac{1}{x}}
The inner fraction automatically shrinks to fit. Still, deeply nested fractions can quickly become unreadable. Two solutions help:
- Use
\dfracfor the inner fraction if you want it larger. - Use
\cfrac, which is designed specifically for continued fractions:
\[
x = a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{a_3}}}
\]
The \cfrac command keeps every level of the fraction at a consistent, readable size, which is exactly what continued fractions demand That's the part that actually makes a difference. Turns out it matters..
Fractions with Complex Expressions
Your numerator and denominator are not limited to single numbers or letters. You can place almost any mathematical content inside the braces:
\frac{\sqrt{x^2 + y^2}}{\sin(\theta)}
\frac{\sum_{i=1}^{n} i}{n}
\frac{\frac{a}{b}}{\frac{c}{d}}
Because the braces group everything together, you never have to worry about LaTeX misinterpreting where the numerator ends. Just make sure your braces are balanced—every opening { needs a closing } Worth keeping that in mind..
Common Mistakes and How to Avoid Them
Even experienced users stumble over fractions occasionally. Here are the most frequent problems and their fixes:
-
Missing math mode. Fractions only work inside math mode. Writing
\frac{1}{2}in regular text triggers an error -
Missing math mode. Fractions only work inside math mode. Writing
\frac{1}{2}in regular text triggers an error. Always wrap your fraction in$...$,\(...\), or\[...\], or place it inside an environment likeequationSimple as that.. -
Unbalanced braces. Every
\fracneeds exactly two arguments. If you forget a closing brace, LaTeX will complain or, worse, silently swallow the text that follows. Count your braces carefully, and let a good editor highlight matching pairs for you. -
Confusing
\fracwith a slash. Writing1/2in math mode does not produce a stacked fraction—it just prints a slash. If you want a compact inline form, that is fine, but for a proper fraction use\fracor the shorthand\frac12(which works because single tokens count as arguments). -
Forgetting that
\fractakes only two arguments. Commands like\frac{a}{b}{c}will leave{c}dangling in your output. Group everything you want in the numerator or denominator inside a single pair of braces.
A Quick Reference Table
| Goal | Command |
|---|---|
| Basic fraction | \frac{a}{b} |
| Large fraction inline | \dfrac{a}{b} |
| Small fraction in display | \tfrac{a}{b} |
| Continued fraction | \cfrac{a}{b} |
| Nested fraction | \frac{\frac{a}{b}}{c} |
Conclusion
Fractions are one of the first things you will typeset in LaTeX, and they are a perfect introduction to how the language thinks: everything is built from simple commands and grouped with braces. Once you understand that \frac takes a numerator and a denominator, and that math mode controls how large and how spaced the result appears, the rest falls into place naturally Worth keeping that in mind..
Start with the plain \frac command, reach for \dfrac and \tfrac when you need precise control over size, and turn to \cfrac when you are writing continued fractions. Keep an eye on the common pitfalls—especially math mode and balanced braces—and you will avoid the vast majority of errors. With a little practice, typesetting even deeply nested expressions will feel effortless, leaving you free to focus on the mathematics itself rather than the markup.