5

Consider the following example:

Code

\documentclass{article}

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

\begin{document}

\begin{table}
 \centering
  \begin{tabular}{l !{\quad} c c D{.}{.}{2.2} !{\quad} c c D{.}{.}{2.2}}
   \toprule
    \multicolumn{1}{c!{\quad}}{Times} & \multicolumn{3}{c!{\quad}}{RAAN} & \multicolumn{3}{c}{Dec}\\
   \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?

3
  • I'd use siunitx' S-columns and maybe \sisetup{table-parse-only}. BTW: there's also \si{\arcminute} and \si{\arcsecond}.
    – cgnieder
    Mar 6 '13 at 22:41
  • I will try to do this. Thank you for the hints. 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.) Mar 6 '13 at 22:59
6

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:

enter image description here

\documentclass{article}

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

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

\begin{document}

\begin{table}
 \centering
  \caption{Something.}
  \label{tbl:1}
  \begin{tabular}{l !{\quad} c c D{.}{.}{2.2} !{\quad} c c D{.}{.}{2.2}}
   \toprule
    \multicolumn{1}{c!{\quad}}{Times} & \multicolumn{3}{c!{\quad}}{RAAN} & \multicolumn{3}{c}{Dec}\\
   \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.

3
  • Very nice, indeed! Mar 6 '13 at 22:48
  • 3
    @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 Mar 6 '13 at 22:54
  • Good point, David! I will do that. Mar 6 '13 at 22:59
5

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.

enter image description here

4
  • 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...
    – cgnieder
    Mar 6 '13 at 23:13
  • Great answer, I must say. Mar 6 '13 at 23:13
  • @cgnieder I had the same thought. :) 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.