Can You Use nicefrac Within siunitx?
At a glance
- 1. Load both packages
Use siunitx for quantities and nicefrac for the fraction’s appearance.
- 2. Turn off number parsing
Set parse-numbers=false for the quantity containing the \nicefrac command.
- 3. Keep units formatted
siunitx can still format the unit even when it treats the number as literal input.
Yes, but siunitx normally parses the number argument before formatting it. The command \nicefrac{1}{2} is formatting markup, not plain numeric input, so the parser may report an invalid number. Disable parsing for that quantity and siunitx can still handle its unit.
Minimal working example
The following example uses the current siunitx v3 command \qty:
\documentclass{article}
\usepackage{siunitx}
\usepackage{nicefrac}
\begin{document}
A half metre is \qty[parse-numbers=false]{\nicefrac{1}{2}}{\metre}.
\end{document}
The output is a nice fraction followed by a properly formatted metre unit. The option applies only to this quantity, so other numbers in the document continue to be parsed and formatted normally.
Why number parsing matters
siunitx is designed to accept numeric input, interpret it, and apply consistent formatting. For instance, it can format decimal markers, signs, exponents, and uncertainty notation. A command such as \nicefrac{1}{2} is instead a LaTeX instruction for how to typeset a fraction. If siunitx tries to interpret that instruction as numeric input, it may not recognize it.
The option parse-numbers=false tells siunitx to treat the supplied number content as literal material. It does not turn off unit formatting: \metre is still processed as a siunitx unit.
Apply the option narrowly
Prefer the local option on the quantity that needs \nicefrac:
\qty[parse-numbers=false]{\nicefrac{3}{4}}{\second}
You can also set the option globally with \sisetup{parse-numbers=false}, but then siunitx will stop parsing every number it receives. That can affect number formatting elsewhere, so use the global setting only if you intentionally want literal number input throughout the document.
If you use siunitx v2, the older quantity command is \SI:
\SI[parse-numbers=false]{\nicefrac{1}{2}}{\metre}
For a new document, use the v3 command \qty with a current siunitx release.
Common mistakes
- Leaving number parsing enabled:
\qty{\nicefrac{1}{2}}{\metre}can fail because the number parser is asked to interpret the\nicefraccommand. - Putting the fraction in the unit argument: The first argument is the quantity’s number; the second is its unit. Keep
\nicefracin the first argument. - Disabling parsing for the whole document unnecessarily: A local option avoids changing how other siunitx numbers are processed.
- Forgetting to load nicefrac: The command
\nicefracis defined by thenicefracpackage, so include\usepackage{nicefrac}.
If you do not need the specific appearance provided by nicefrac, supplying a numeric value in a form siunitx parses—such as 0.5—is often simpler.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.