The nicefrac package

Provides \nicefrac{1}{2} for small diagonal fractions such as ½ in running text and in formulas.

Loading the package

\usepackage{nicefrac}

\frac{1}{2} works in math mode only, and inside a line of text it is taller than the letters around it. 1/2 sets both digits in full size. \nicefrac{1}{2} raises a small numerator, lowers a small denominator and puts a slash between them, so the fraction has the height of a text line.

The command works in text and in math mode. The package belongs to the units bundle; \usepackage{units} loads it too. xfrac does the same job with separate settings per font family.

Main commands

\nicefrac{1}{2}Diagonal fraction in the current font.
\nicefrac[\textit]{1}{2}The optional argument is a font command for numerator and denominator.
\usepackage[ugly]{nicefrac}Switches all fractions to a plain form: 1/2 in text, a stacked fraction in math.

Complete example

\documentclass{article}
\usepackage{nicefrac}
\begin{document}
Add \nicefrac{1}{2} cup of sugar and \nicefrac{3}{4} cup of flour.

In a formula: $x^{\nicefrac{1}{2}} = \sqrt{x}$ and
$\nicefrac{a}{b} + \nicefrac{c}{d}$.

For comparison: 1/2, \nicefrac{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