Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to center column headings (and column headings only) in the following table. Why does it work with the first column, but not the second (I thought \multicolumn is the correct approach to this problem).

\documentclass{article}

\usepackage[american]{babel}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}
\begin{tabular}{rr}
  \toprule
  \multicolumn{1}{c}{$\alpha$} & \multicolumn{1}{c}{$\alpha=0.99999$} \\
  \midrule
  10     & 69.681   \\
         & 901.741  \\
  1000   & 893.630  \\
         & 82.806   \\
  \bottomrule
\end{tabular}
\end{document}
share|improve this question
    
the second column is centered; could you clarify what you were hoping for? –  cmhughes Sep 23 '12 at 0:34
    
I was hoping that the right-aligned entries are moved sufficiently to the left so that the column label looks more centered than right-aligned. –  Marius Hofert Sep 23 '12 at 0:49

4 Answers 4

up vote 3 down vote accepted

This is just a little example of how you can make a small modification to your input in order to get the desired output:

enter image description here

\documentclass{article}
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\begin{document}
\begin{tabular}{rc}
  \toprule
  \multicolumn{1}{c}{$\alpha$} & $\alpha=0.99999$ \\
  \midrule
  10     & \phantom{0}69.681   \\
         & 901.741  \\
  1000   & 893.630  \\
         & \phantom{0}82.806   \\
  \bottomrule
\end{tabular}
\end{document}

The addition of a \phantom leading 0 for numbers less then 100 makes all the numbers the same width, so centering is readily achieved.

share|improve this answer
    
Thanks, Werner, nice idea. –  Marius Hofert Sep 23 '12 at 1:28

Here's a solution using siunitx column formatting

enter image description here

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{tabular}{
  r
  S[
      table-format = 3.3,
      input-symbols=.,
  ]
  }
    \toprule
    \multicolumn{1}{c}{$\alpha$} & \multicolumn{1}{c}{$\alpha=0.99999$} \\
    \midrule
    10     & 69.681   \\
           & 901.741  \\
    1000   & 893.630  \\
           & 82.806   \\
    \bottomrule
\end{tabular}

\end{document}
share|improve this answer

Using the dcolumn package you can get the desired alignment automatically:

\documentclass{article}
\usepackage{booktabs}
\usepackage{dcolumn}

\newcolumntype{M}{D{.}{.}{3.3}}

\begin{document}

\begin{tabular}{rM}
\toprule
\multicolumn{1}{c}{$\alpha$} & \multicolumn{1}{c}{$\alpha=0.99999$} \\
\midrule
10     & 69.681   \\
       & 901.741  \\
1000   & 893.630  \\
       & 82.806   \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

share|improve this answer

It is centered correctly. The problem is the length (width) of numbers in that column that are right aligned. I mean to say α = 0.99999 is longer than any of the numbers in that column. As a proof, let us put a slightly bigger number.

\documentclass{article}

\usepackage[american]{babel}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}
\begin{tabular}{rr}
  \toprule
  \multicolumn{1}{c}{$\alpha$} & \multicolumn{1}{c}{$\alpha=0.99999$} \\
  \midrule
  10     & 69.681   \\
         & 901.741  \\
  1000   & 893.630  \\
         & 82.80600000000000000000   \\
  \bottomrule
\end{tabular}
\end{document}

enter image description here

share|improve this answer
    
Argh... you are right, I didn't check that. Thanks! –  Marius Hofert Sep 23 '12 at 0:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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