15

I am using the siunitx package to typeset my numbers, but sometimes I find situations in which I have numbers without units (when the units are not nearby) and units without numbers. E.g.:

The bird can fly 40 to 50 km per hour.

The data in the table above uses kg.

What is the prefered way to typeset these?

The bird can fly $40$ to $\SI{50}{\kilo\meter\per\hour}$.

The bird can fly \num{40} to \SI{50}{\kilo\meter\per\hour}.

The bird can fly \SI{40}{} to \SI{50}{\kilo\meter\per\hour}.

The data in the table above uses kg.

The data in the table above uses \SI{}{\kilo\gram}.

If find achieving visual consistency and correctness in the output is more important than having consistent, context-intelligent code.

1 Answer 1

28

To typeset units without numbers, you can use \unit{<unit>} (or \si - used in v2 - note the lower case).

To typeset numbers without units, you can use \num{<number>}.

The mathematically correct way to typeset ranges of values with units is to include the unit with each of the numbers. This is what the command \qtyrange{<lower>}{<upper>} (or SIrange) does. If you don't want to repeat the units, you can set [range-units = single].

Note that the most common units can be accessed using abbreviations (like \km for \kilo\metre).

\documentclass{article}
\usepackage{siunitx}

\begin{document}
The bird can fly \qtyrange{40}{50}{\km\per\hour}.

The bird can fly \qtyrange[range-units=single]{40}{50}{\km\per\hour}.

The data table above uses \unit{\kg}.

There  are \num{12345} birds in the sky.
\end{document}
4
  • 1
    What about "The bird can fly 40 or 50 km/h?"
    – bers
    Commented Apr 6, 2015 at 20:01
  • 1
    You can use the \SIlist{} command: \SIlist[list-pair-separator = { or }, list-units=single]{40; 50}{\kilo\meter\per\hour}.
    – applesoup
    Commented Oct 26, 2017 at 20:42
  • Unfortunately, this is the top hit on google for how to typeset numbers without units with this package, and this does not answer that part of the question from the title
    – penelope
    Commented Apr 26 at 10:31
  • @penelope I have expanded the answer to include that use case as well
    – Jake
    Commented Apr 26 at 11:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .