21

How do I print \frac{4}{3} m/s using the siunitx package?

$\SI{\frac{4}{3}}{m/s}$ gives an error.

  • 3
    The \num and \SI commands have an optional argument, $\SI[parse-numbers=false]{\frac{4}{3}}{\meter/\second}$, but $\frac{4}{3}$ \si{\meter/\second} could be a better approach –  Jan 15 '17 at 17:06
  • 1
    In addition to Boris' answer, note that it might be better to write \SI{3/4}{\meter\per\second}, and have \sisetup{quotient-mode=fraction,per-mode=symbol}. If you decide at some point to use units of the form m s^{-1}, then you just need to remove the per-mode=symbol from the \sisetup. – Torbjørn T. Jan 15 '17 at 21:21
  • @TorbjørnT. I suggest editing Boris' answer to include this information as it is what I was looking for. – Toivo Säwén Feb 18 '19 at 11:04
  • I am voting to close this as a duplicate of the question asking about the removal of this functionality as people reading this question will find the information they need there (even though the question is not literally a duplicate). – schtandard Aug 13 '22 at 12:04

1 Answers1

25

SIunitx can output fractions if you (1) tell it to do this, and (2) write down input as a/b:

\documentclass{minimal}
\usepackage{siunitx}
\begin{document}
\sisetup{quotient-mode=fraction} % Output a/b as \frac{a}{b}
\SI{3/4}{\meter/\second}
\end{document}

enter image description here

You can set the quotient mode on a case by case basis:

\SI[quotient-mode=fraction]{3/4}{\meter/\second}

or change the fraction macro:

\SI[quotient-mode=fraction, fraction-function=\dfrac]{3/4}{\meter/\second} 
% Need amsmath for \dfrac
Boris
  • 38,129