The siunitx package

Typesets numbers and physical quantities with consistent spacing and units: \qty, \num, \unit, and the table column S that aligns numbers at the decimal marker.

Loading the package

\usepackage{siunitx}

A quantity typed by hand, such as 3.2 m/s, goes wrong in several ways: the unit turns italic in math mode, a line can break between number and unit, and the notation differs from chapter to chapter. \qty{3.2}{\meter\per\second} sets an upright unit, a thin space that does not break, and one notation for the whole document.

Units are written with macros (\kilo\gram, \meter\per\second\squared) or as literal text (kg.m/s^2). \sisetup changes the output for all quantities at once, for example fractions instead of negative exponents, or a decimal comma.

Version 3 from 2021 introduced the names \qty, \unit and \qtyrange. The older names \SI, \si and \SIrange still work in version 3.

Main commands

\qty{3.2}{\meter\per\second}Number with unit. Older name: \SI.
\num{6.022e23}Number alone: groups the digits in threes and writes e23 as a power of ten.
\unit{\kilo\gram}Unit alone. Older name: \si.
\qtyrange{20}{25}{\celsius}Range of values with one unit. Older name: \SIrange.
\ang{45}Angle in degrees; \ang{1;2;3} gives degrees, minutes and seconds.
\sisetup{per-mode = symbol}Sets options for the rest of the document; here \per prints a slash instead of a negative exponent.
\begin{tabular}{l S[table-format=3.2]}Column type S aligns numbers at the decimal marker; table-format=3.2 reserves 3 digits before and 2 after it.

Complete example

\documentclass{article}
\usepackage{siunitx}
\sisetup{per-mode = symbol}
\begin{document}
The car reaches \qty{27.8}{\meter\per\second} after \qty{9.3}{\second}.
The resistor has \qty{4.7}{\kilo\ohm}, the room \qtyrange{20}{25}{\celsius}.
Avogadro constant: \num{6.022e23}. Angle: \ang{45}.
Torque is measured in \unit{\newton\meter}.

\begin{tabular}{l S[table-format=3.2]}
Sample & {Mass in \unit{\gram}} \\ \hline
A & 12.5   \\
B & 104.25 \\
C & 7.03   \\
\end{tabular}
\end{document}
Result
The compiled example

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023.

Pitfalls

Related pages