Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
To set a fraction with a slash in LaTeX, load xfrac and write \sfrac{1}{2}, or load nicefrac and write \nicefrac{1}{2}. Both produce a small raised numerator, a slash and a lowered denominator that sits inside the line of text instead of stretching the line spacing the way a stacked \frac does. The nicefrac package’s own CTAN page says the experimental xfrac package provides the same facilities “in a cleaner way”, so \sfrac is the better default for new documents.
What it is used for in research
Slashed fractions are used where a stacked fraction would break up a line of running text: quantities in methods sections (a half-dose of a reagent, a three-quarter-power scaling law), units written as ratios, and table cells where height is tight. The nicefrac documentation describes its purpose as typesetting in-line fractions in a nice way, with the numerator kept no taller than the letter “M” and the denominator kept at or above the baseline, so the line spacing is not stretched.
The two packages answer the same question with different engineering. nicefrac (version 0.9b, dated 1998-08-04) builds the fraction from scaled characters. xfrac (released 2024-06-04 by The LaTeX Project) builds “split-level fractions” from templates and font instances, so it can adapt to the font family in use. For stacked display fractions see the guide to \dfrac; for division symbols and the basic \frac see division in LaTeX.
Install or access
Both packages are distributed through CTAN, the Comprehensive TeX Archive Network, and are the official sources for this page.
- xfrac: CTAN lists it as “split-level fractions”, version 2024-06-04, available in TeX Live and MiKTeX. Its documentation is
xfrac.pdf. - nicefrac: CTAN lists it as “Typeset in-line fractions in a nice way”, version 0.9b, licensed under the GNU GPL, copyright 1998 Axel Reichert (maintainer). It ships inside the
unitsbundle, so loadingunitsalso provides the fraction command.
If your distribution is a full TeX Live or MiKTeX installation, the package manager can fetch either one on demand; in an online editor you only need the usepackage line.
Step-by-step: set a slashed fraction
With xfrac (recommended)
- In the preamble add
\usepackage{xfrac}. - In text or math mode write
\sfrac{1}{2}. The documented examples include\sfrac{1}{2}in text,$\sfrac{1}{2}$in math and$\mathbf{3\times\sfrac{1}{2}}$for a bold expression, and they work across fonts such as Palatino and Times. - For a mixed number, put the whole number before the command, for example
3\sfrac{1}{2}. The general syntax is\sfrac[instance]{numerator}[separator]{denominator}, where the optional arguments select a font instance and a separator.
With nicefrac
- In the preamble add
\usepackage{nicefrac}to get only the fractions, or\usepackage{units}to get the whole bundle. - Write
\nicefrac{1}{2}. The full syntax is\nicefrac[fontcmd]{numerator}{denominator}; the optionalfontcmdcan be an author command for fonts or a math alphabet. - Choose the style with a package option:
\usepackage[nice]{nicefrac}(the default) or\usepackage[ugly]{nicefrac}. Withugly, fractions look like m/s in text mode and like a stacked\fracin math mode.
The no-package fallback
In math mode, typing a/b gives a plain slash with no raised numerator. It needs no package and is the right choice for inline ratios such as $\mu/\sigma$, but it does not shrink the numerator and denominator.
Output and how to read it
A split-level fraction reads as numerator raised, slash, denominator lowered, all at a reduced size. The difference between the two packages is in the slash itself. The xfrac authors explain that the TeXbook’s first exercise produced a split-level fraction with a virgule, while the proper separator is a solidus, which does not exist in Computer Modern but does in the EC fonts. Accordingly:
- In text mode,
\sfracdefaults to the solidus (textfractionsolidusfromtextcomp). - In math mode it uses the virgule instead, because, in the xfrac documentation’s words, “the solidus is a text symbol only”.
- With Computer Modern fonts, the default
cm-recommendedoption borrows the Times solidus for Computer Modern Roman and Sans, and the Palatino solidus for Computer Modern Typewriter. Thecm-standardoption stays with Computer Modern only.
The xfrac authors list four problems they set out to fix in nicefrac: it uses the virgule instead of the solidus; its numerator and denominator are larger than those in the built-in textonehalf symbol; it does not correct for text (old-style) figures; and in math mode it does not always select the correct math alphabet.
Which command to use
| Command | Typical use | Source of the behaviour |
|---|---|---|
\sfrac{1}{2} (xfrac) |
Inline fractions in new documents; works in text and math | xfrac documentation, 2024-06-04 |
\nicefrac{1}{2} (nicefrac) |
Existing documents already using nicefrac or the units bundle | nicefrac documentation (units.dtx), v0.9b |
a/b in math mode |
Plain ratio such as a rate or normalised value, no size change | Standard LaTeX math mode |
\frac{a}{b} |
Stacked fraction; may stretch the line when used in running text | Standard LaTeX, see the division guide |
The data table below the guide compares the two packages attribute by attribute, with the date each source was read.
Tuning the font: a worked instance
Because \sfrac picks an instance named after the current font family, you can override the slash font without touching the document body. The xfrac documentation gives these declarations:
\DeclareInstance{xfrac}{cmr}{text}{slash-symbol-font = ptm}
This makes Computer Modern Roman use the Times solidus. For old-style figures the documentation gives:
\DeclareInstance{xfrac}{cmor}{text}{slash-symbol-font = ptm, numerator-font = cmr, denominator-font = cmr}
The text-template keys are numerator-font, numerator-format, slash-symbol, slash-symbol-font, slash-symbol-format, denominator-font, denominator-format, h-scale (default 1), v-scale (default 1) and scale-factor. In math mode the mathdefault instance uses whichever math family is active, and TeX allows at most 16 math families.
When a slashed fraction is the wrong tool
The nicefrac documentation says the package is meant for relatively simple numerators and denominators, and that using it for complex formulas is a misuse. If the numerator or denominator contains a sum, a subscript chain or a nested fraction, a slash can be read two ways, so use a stacked \frac in a display equation instead. The nicefrac authors also warn that the ugly option in text mode can produce ambiguous fractions, which is why the package issues a warning there.
A practical rule that follows from both documentation sets: reserve \sfrac or \nicefrac for short, single-symbol or numeric parts such as \sfrac{3}{4} in running prose, and keep anything longer in a displayed equation. When a document must be consistent across several fonts, the xfrac instance mechanism lets you define the slash font once in the preamble rather than editing each fraction. Because the same command works in text and math mode in both packages, switching a document from one to the other is mostly a search-and-replace of the command name plus a change to the preamble.
Troubleshooting
A warning about an ambiguous fraction
The nicefrac documentation notes that the ugly option in text mode can give ambiguous fractions, and the package issues a warning. Switch back to nice or rewrite the expression.
Odd spacing or sizes
The nicefrac documentation lists these shortcomings: fonts that lack the letter “M” misbehave, fractions in scriptscriptstyle exceed the “M” height, and there is no kerning between the numerator, the denominator and the slash. The package is intended for relatively simple numerators and denominators; complex formulas are a misuse and belong in \frac.
Error when the command sits in a section title
Optional arguments nested inside another optional argument need braces. The nicefrac documentation’s example is \section[{\unit[1]{m}}]{...}; the same bracing logic applies to a fraction placed in the short title of \section[...].
Slash looks wrong in a specific font
Declare an xfrac instance for that font family as shown above, or change slash-symbol-font.
Free alternatives
Both packages are free. \nicefrac is licensed under the GNU GPL per its CTAN page, and both are distributed through TeX Live and CTAN.
| Option | What you get | Limit stated by its documentation |
|---|---|---|
| xfrac | Instance-based split-level fractions, solidus in text mode | Math mode uses the virgule; the solidus is a text symbol only |
| nicefrac | Scaled in-line fractions with nice and ugly options | Needs a font with “M”; no kerning around the slash |
Plain a/b |
A slash with no package | No reduced numerator or denominator |
FAQ
How do I write a fraction with a slash in LaTeX?
Load xfrac and write \sfrac{1}{2}, or load nicefrac and write \nicefrac{1}{2}. In math mode, plain 1/2 also works if you do not need smaller numerals.
Should I use nicefrac or xfrac?
For new documents use xfrac. The CTAN page for nicefrac describes xfrac as providing the same facilities in a cleaner way. Keep \nicefrac if an existing document or the units bundle already depends on it.
Why does my math-mode slash look different from the text-mode one?
In math mode \sfrac uses a virgule, because the solidus is a text symbol only, according to the xfrac documentation.
Can I use these commands in both text and math mode?
Yes. Both packages document the same command in text and math mode.
Sources
- CTAN, nicefrac package page, read 2026-11-12.
- CTAN, xfrac package page, read 2026-11-12.
- CTAN, units.dtx (nicefrac documentation source), read 2026-11-12.
- The LaTeX Project, xfrac.dtx (xfrac documentation source, released 2024-06-04), read 2026-11-12.
Data: nicefrac and xfrac package attributes for in-line slashed fractions
Side-by-side attributes of the nicefrac and xfrac LaTeX packages compiled from the CTAN package pages and the packages' own documentation sources (units.dtx and xfrac.dtx).
| Attribute | nicefrac | xfrac |
|---|---|---|
| Main command | \nicefrac[fontcmd]{num}{denom} | \sfrac[instance]{num}[sep]{denom} |
| Documented version | 0.9b (1998-08-04) | 2024-06-04 |
| CTAN description | Typeset in-line fractions in a nice way | Split-level fractions |
| Distribution | Ships in the units bundle | TeX Live and MiKTeX |
| Separator in text mode | Virgule (per xfrac authors) | Solidus (textfractionsolidus) |
| Separator in math mode | Virgule (per xfrac authors) | Virgule |
| Style options | nice (default), ugly | Instances and keys via DeclareInstance |
| Font tuning | Optional fontcmd argument | Keys such as slash-symbol-font, numerator-font, h-scale, v-scale |
Sources
- CTAN nicefrac package page (accessed 2026-11-12)
- CTAN xfrac package page (accessed 2026-11-12)
- units.dtx (nicefrac documentation) (accessed 2026-11-12)
- xfrac.dtx (xfrac documentation) (accessed 2026-11-12)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







