Skip to content

Instantly share code, notes, and snippets.

@FedericoTartarini
Created June 14, 2022 15:23
Show Gist options
  • Save FedericoTartarini/126a7274c1ffea72ae216b731bdb5452 to your computer and use it in GitHub Desktop.
Save FedericoTartarini/126a7274c1ffea72ae216b731bdb5452 to your computer and use it in GitHub Desktop.
How to use the siunitx LaTeX package
\documentclass[12pt]{article}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{locale = DE, per-mode = symbol, range-phrase=--, range-units=single, product-units=single}
\begin{document}
\section*{siunitx package}
$5 m/s$ \\
$5 \mathrm{m}/\mathrm{s}$ \\
$5\unit{\m\per\s}$ \\
$\qty{5}{\m\per\s} + \qty{5}{\m\per\s}$
\subsection*{Numbers}
\num{123} \\
\num{1234} \\
\num{12345} \\
\num{0.123} \\
\num{0,1234} \\
\num{.12345} \\
\num{3.45d-4} \\
\num{3.45e-4} \\
\num{-e10} \\
\num[locale = DE]{6.789}
\subsection*{List of numbers}
\numlist{10;20;25;30}
\subsection*{Angles}
\ang{10} \\
\ang{12.3} \\
\ang{4,5} \\
\ang{1;2;3} \\
\ang{;;1} \\
\ang{+10;;} \\
\ang{-0;1;}
\subsection*{Units}
\unit{\m\candela} \\
\unit{kg.m.s^{-1}} \\
\unit{\kilogram\metre\per\second} \\
\unit{\kg\m\per\s} \\
\unit[per-mode = symbol]{\kilogram\metre\per\ampere\per\second}\\
\unit{\kilo\gram\metre\per\square\second} \\
\unit[per-mode = symbol]{\gram\per\cubic\milli\metre} \\
\unit{\square\volt\cubic\lumen\per\farad} \\
\unit{\metre\squared\per\cubic\lux} \\
\unit{\henry\second}
\subsection*{Numbers with units}
\qty{10}{\celsius} \\
\qty{10}{\degreeCelsius} \\
\qty{1.23}{J.mol^{-1}.K^{-1}} \\
\qty{.23e7}{\candela} \\
\qty[per-mode = symbol]{1.99}{\per\kilogram} \\
\qty[per-mode = fraction]{1,345}{\coulomb\per\mole}
\subsubsection*{Additional macros for numbers with units}
\qtylist{0.13;0.67;0.80;1}{\milli\metre}\\
\numproduct{1.654 x 2.34 x 3.430} \\
\qtyproduct{10 x 30 x 45}{\metre} \\
\numrange{10}{20} \\
\numrange[range-phrase=--]{10}{20} \\
\qtyrange{0.13}{0.67}{\milli\metre} \\
\subsection*{Complex numbers}
\complexnum{1 + i}
\clearpage
\subsection*{Tables}
\begin{table}[h!]
\centering
\caption{Standard behaviour of the \texttt{S} column type.%
\label{tab:S:standard}}
\begin{tabular}{@{}S@{}}
\toprule
{Some Values} \\
\midrule
2.3456 \\
34.2345 \\
-6.7835 \\
90.473 \\
5642.5 \\
1.2e3 \\
e4 \\
\bottomrule
\end{tabular}
\end{table}
\begin{table}[h!]
\caption{Aligning the \texttt{S} column.%
\label{tab:S:align}}
\centering
\sisetup{table-format = 2.4, table-alignment-mode = format}
\begin{tabular}{@{}
S[table-alignment-mode = marker]
S[table-number-alignment = center]
S[table-number-alignment = left]
S[table-number-alignment = right]
@{}}
\toprule
{Some Values} & {Some Values} & {Some Values} & {Some Values} \\
\midrule
2.3456 & 2.3456 & 2.3456 & 2.3456 \\
34.2345 & 34.2345 & 34.2345 & 34.2345 \\
56.7835 & 56.7835 & 56.7835 & 56.7835 \\
90.473 & 90.473 & 90.473 & 90.473 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment