The xfrac package

Provides \sfrac{1}{2} for diagonal fractions such as ½, with sizes and spacing set per font family.

Loading the package

\usepackage{xfrac}

\sfrac builds a split-level fraction: a small raised numerator, a slash and a small lowered denominator. The fraction fits into a text line and into an exponent, where \frac would be too tall.

The command works in text and in math mode. Compared with nicefrac, xfrac brings its own size and spacing settings for the Computer Modern and Latin Modern families in roman, sans serif and typewriter.

Main commands

\sfrac{1}{2}Diagonal fraction in text.
$x^{\sfrac{1}{2}}$The same command in math mode, here in an exponent.
\sfrac{3}[ of ]{4}The optional argument in the middle replaces the slash.

Complete example

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{xfrac}
\begin{document}
Mix \sfrac{1}{2} litre of milk with \sfrac{3}{4} cup of flour.

In a formula: $x^{\sfrac{1}{2}} = \sqrt{x}$ and $\sfrac{a}{b}$.

For comparison: 1/2, \sfrac{1}{2} and $\frac{1}{2}$.
\end{document}
Result
The compiled example

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023.

Pitfalls

Related pages