# Properly align numbers with units in table

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}

-

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.

-
That's a good idea! I've adapted it a bit to use the \si macro for typesetting the unit, and defined a new column type that takes a parameter for setting the width of the unit box. \newcolumntype{U}[1]{>{\hmm{#1}}r} \def\hmm#1{% \def\SI##1##2{$##1$\,\makebox[#1][l]{\si{##2}}}% }. Works great. Thank you! –  Jake Apr 17 '12 at 22:29

The standards of good typography do not recommend putting the values and units in the same column: this makes the table cluttered. The books I've read say that it is better to have a special column for units. Siunitx have the s column for this:

\documentclass{article}
\usepackage{siunitx,booktabs}
\pagestyle{empty}
\begin{document}
\begin{tabular}{lsS}
\toprule
Entry & \multicolumn{1}{c}{Units} & \multicolumn{1}{c}{Value}\\
\midrule
A & \day & 1\\
B & \minute & 30\\
C & \minute & 5\\
\bottomrule
\end{tabular}

\end{document}


-
I'd go this way but with the columns swapped and appropriate alignment settings to look like one column :-) –  Joseph Wright Apr 17 '12 at 20:54
This is smart :) But I so much used to formal tables where units precede the values... –  Boris Apr 17 '12 at 20:58
It would depend on the real use case. One case where you do need the units is a table of physical constants: the sort of thing you get in a textbook on physics, physical chemistry, etc. –  Joseph Wright Apr 17 '12 at 21:03
@Boris: Thanks for the answer! In general, I'd agree with you, but in this case, I'll consciously choose to break the typographical rule =) –  Jake Apr 17 '12 at 22:42
well, using @JosephWright suggestion above you can put the units just after the numbers :) –  Boris Apr 18 '12 at 3:00