Skip to main content
v2026.11,986 entries · CC-BY 4.0

LaTeX Fraction Slash: \nicefrac and \sfrac Explained

Set a slashed in-line fraction in LaTeX with \sfrac from xfrac or \nicefrac from nicefrac, and learn why the math-mode slash differs from text mode.

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 units bundle, so loading units also 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

  1. In the preamble add \usepackage{xfrac}.
  2. 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.
  3. 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

  1. In the preamble add \usepackage{nicefrac} to get only the fractions, or \usepackage{units} to get the whole bundle.
  2. Write \nicefrac{1}{2}. The full syntax is \nicefrac[fontcmd]{numerator}{denominator}; the optional fontcmd can be an author command for fonts or a math alphabet.
  3. Choose the style with a package option: \usepackage[nice]{nicefrac} (the default) or \usepackage[ugly]{nicefrac}. With ugly, fractions look like m/s in text mode and like a stacked \frac in 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, \sfrac defaults to the solidus (textfractionsolidus from textcomp).
  • 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-recommended option borrows the Times solidus for Computer Modern Roman and Sans, and the Palatino solidus for Computer Modern Typewriter. The cm-standard option 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

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).

nicefrac and xfrac package attributes for in-line slashed fractions
Attributenicefracxfrac
Main command\nicefrac[fontcmd]{num}{denom}\sfrac[instance]{num}[sep]{denom}
Documented version0.9b (1998-08-04)2024-06-04
CTAN descriptionTypeset in-line fractions in a nice waySplit-level fractions
DistributionShips in the units bundleTeX Live and MiKTeX
Separator in text modeVirgule (per xfrac authors)Solidus (textfractionsolidus)
Separator in math modeVirgule (per xfrac authors)Virgule
Style optionsnice (default), uglyInstances and keys via DeclareInstance
Font tuningOptional fontcmd argumentKeys such as slash-symbol-font, numerator-font, h-scale, v-scale

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about LaTeX Fraction Slash: \nicefrac and \sfrac Explained

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →