# Can I use nicefrac within siunitx?

I suspect the answer is a straight 'No', but nothing ventured... I have a table of time periods (minutes and hours), and a couple of the periods involve the fraction 1/2. I generally use the \SI macro of the siunitx package for numbers and units, as it gives a nice spacing between the number and the unit. I could use 0.5 rather than the fraction 1/2, but in this particular case the fraction is more aesthetically and stylistically pleasing. I have tried using the \nicefrac{1}{2} macro within the first brackets of the \SI{*number*}{*unit*} macro, but it does not seem to work. Is there another way of achieving the same objective?

MWE as follows:

\documentclass[a4paper,11pt]{scrreprt}
\usepackage[english]{babel}
\usepackage{siunitx}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{nicefrac}

\begin{document}
A nice fraction: 2\nicefrac{1}{2}.

Some time periods:

\SI{1}{\minute}

\SI{5}{\minute}

\SI{2}{\hour}

The above all works fine.

% This, however, does not:

% \SI{2\nicefrac{1}{2}}{\minute}

\end{document}

• \SI[fraction-function=\nicefrac,quotient-mode = fraction]{1/2}{\minute} would work if the num is only a quotient. But I have no idea how to add the "2" before it. Addition: Well \SI[fraction-function=\nicefrac,quotient-mode = fraction,product-units = single,output-product={\,}]{2x1/5}{\minute} seems to work. – Ulrike Fischer Oct 13 '14 at 10:06
• But 2x1/5 is naturally mathematically dubious ... – Ulrike Fischer Oct 13 '14 at 10:12
• Your solution also works perfectly @Ulrike_Fischer, but I've gone with Joseph's because of its simplicity. – Mark Birtwistle Oct 13 '14 at 20:30

For cases where you want to do things beyond the understanding of the siunitx internals, you can turn the parser off

\SI[parse-numbers = false]{2\nicefrac{1}{2}}{\minute}


The option fraction-function=\nicefrac option will do just that, but you'll need to load the package nicefrac and set quotient-mode = fraction as well.

\documentclass{standalone}

\usepackage{nicefrac}
\usepackage{siunitx}

\sisetup{
quotient-mode = fraction,
fraction-function=\nicefrac
}

\begin{document}
\nicefrac{1}{3} \num{1/3}
\end{document}


• This works well for numbers. I tried it with \si{\kilogram / \square \meter}, which gives different results :-( – Jan Feb 8 '19 at 7:06