[Tex/LaTex] Properly align numbers with units in table

horizontal alignmentsiunitxtables

I need to typeset a table comparing, among other things, the temporal resolution of certain datasets. Ordinarily, I would put the common unit into the table header, and only list the values in the table body. However, in this case, some datasets have a resolution of 5 minutes, others of 1 day, which makes the use of the same units awkward (they would either be 5 min and 1440 min, or 0.00347222 d and 1 d).

I'd like to align these values along the space between the values and units, and ideally I'd like to keep the unit/value pairs as logical entities (i.e. to type \SI{1}{\day} or \SI{5}{\minute}, as I would in other contexts). It seems the S column type provided by siuntix doesn't align unit/value pairs provided using the \SI command, but centres them.

MWE (I'd like the entries to be aligned along the space between values and units):

\documentclass{article}
\usepackage{siunitx}

\begin{document}
\begin{tabular}{S}
\SI{1}{\day}\\
\SI{30}{\minute}\\
\SI{5}{\minute}
\end{tabular}

\end{document}

Best Answer

siunitx may have features for this but...

\documentclass{article}
\usepackage{siunitx}

\def\hmm{%
  \def\day{d}\def\minute{min}%
  \def\SI##1##2{$##1\,\makebox[3em][l]{##2}$}}

\begin{document}
\begin{tabular}{>{\hmm}r}
\SI{1}{\day}\\
\SI{30}{\minute}\\
\SI{5}{\minute}
\end{tabular}

\end{document}

seems to do what you ask.

Related Question