# Table alignment

Consider the following example:

Code

\documentclass{article}

\usepackage{siunitx}
\usepackage{booktabs,dcolumn,array}

\begin{document}

\begin{table}
\centering
\toprule
\midrule
& \si{\hour} & \si{\minute} & \si{\s} & \ensuremath{^\circ} & \ensuremath{\prime} & \ensuremath{\prime\prime} \\
\midrule
11{:}40{:}28 & 00 & 03 & 45.48 & 18 & 40 & 03.78 \\
\bottomrule
\end{tabular}
\end{table}

\end{document}


Why are s not centered above 45.48 and \prime\prime not centered above 03.78 and how do I achieve this?

-
I'd use siunitx' S-columns and maybe \sisetup{table-parse-only}. BTW: there's also \si{\arcminute} and \si{\arcsecond}. –  clemens Mar 6 '13 at 22:41
I will try to do this. Thank you for the hints. –  Svend Tveskæg Mar 6 '13 at 22:52
@cgnieder Could you maybe show me how to use the S-columns in this case, since I am not exactly sure how to use it? (My tries give a wrong alignment.) –  Svend Tveskæg Mar 6 '13 at 22:59

dcolumn columns line up entries without a . as if they are integers, so your headings are right aligned to the position of the decimal point in the column. You can use \multicolumn{1} to supply different formatting for the cell:

\documentclass{article}

\usepackage{siunitx}
\usepackage{booktabs,dcolumn,array}

\newcolumntype{d}[1]{D{.}{.}{#1}}

\begin{document}

\begin{table}
\centering
\caption{Something.}
\label{tbl:1}
\toprule
\midrule
& \si{\hour} & \si{\minute} & \multicolumn{1}{c !{\quad}}{\si{\s}} & \ensuremath{^\circ} & \ensuremath{\prime} &  \multicolumn{1}{c}{\ensuremath{\prime\prime} }\\
\midrule
11{:}40{:}28 & 00 & 03 & 45.48 & 18 & 40 & 03.78 \\
\bottomrule
\end{tabular}
\end{table}

This is Table~\ref{tbl:1}.

\end{document}


As an aside since you are loading siunitx anyway you may want to use its S column rather than my dcolumn code.

-
Very nice, indeed! –  Svend Tveskæg Mar 6 '13 at 22:48
@SvendMortensen by the way it would look nicer if you used just \circ rather than ^\circ or use $'$ and $''$ so that all three were textsize or all three superscript, currently circ is small and raised and the primes are full size on the baseline –  David Carlisle Mar 6 '13 at 22:54
Good point, David! I will do that. –  Svend Tveskæg Mar 6 '13 at 22:59

Here's an implementation with siunitx features:

\documentclass{article}

\usepackage{siunitx}
\usepackage{booktabs,array}

\begin{document}

\begin{table}
\centering
\begin{tabular}{
c
S[table-format=2.0,minimum-integer-digits=2]
S[table-format=2.0,minimum-integer-digits=2]
S[table-format=2.2,minimum-integer-digits=2]
S[table-format=2.0,minimum-integer-digits=2]
S[table-format=2.0,minimum-integer-digits=2]
S[table-format=2.2,minimum-integer-digits=2]
}
\toprule
Times & \multicolumn{3}{c}{RAAN} & \multicolumn{3}{c}{Dec}\\
\midrule
& \si{\hour} & \si{\minute} & \si{\s} & \si{\degree} & \si{\arcminute} & \si{\arcsecond} \\
\midrule
11{:}40{:}28 & 00 & 03 & 45.48 & 18 & 40 & 03.78 \\
\bottomrule
\end{tabular}
\end{table}

\end{document}


Instead of adding minimum-integer-digits=2 to each column specifier, a \sisetup{minimum-integer-digits=2} could be made inside the table environment, so it would disappear after it. I just wrote a specifier and copied it five other times, so this is not a big nuisance when typing.

The difference is that if one column doesn't need the setting, the option should be specified. If all S columns share a setting, it may be convenient to use \sisetup.

-
Wouldn't it be easier to add \sisetup{minimum-integer-digits=2} to the table instead of adding it to every column? Except of course one wants to be able to easily change it for a single column later on... –  clemens Mar 6 '13 at 23:13
Great answer, I must say. –  Svend Tveskæg Mar 6 '13 at 23:13
@cgnieder I had the same thought. :) –  Svend Tveskæg Mar 6 '13 at 23:14
@cgnieder I did it in the first version, but this might not what is really desired. I'll add a note about it, thanks. –  egreg Mar 6 '13 at 23:15