[Tex/LaTex] Align numbers on decimal point in tabular except for the column title

dcolumnhorizontal alignmentspacingtables

I am trying to align some numbers in a tabular on the decimal point. I have been using the dcolumn option but given that my column title is a year, it aligns also the year on the decimal point, which I do not want.

Here is my MWE :

\documentclass{beamer}

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

\begin{document}

\begin{frame}{title} 

\begin{table}[H]
\centering
\begin{tabular}{|l|d{4.6}|c|c|} % I just did it for one to see the result
\hline 
\textbf{Poste}  & \textbf{2000} & \textbf{2005} & \textbf{2010} \\  \hline
Alimentation -           b1  & -0.034***  & -0.036**  & -0.016***  \\
Alcool et Tabac -        b2  & -0.009***  & -0.006    & -0.011***  \\
Habillement -            b3  &  0.004     &  0.001    &  0.001     \\
Logement -               b4  & -0.067***  & -0.106*** & -0.073***  \\
Meuble/Entretien -       b5  &  0.019***  &  0.016*** &  0.001***  \\
Santé -                  b6  & -0.001     &  0.005    &  0.036     \\
Transport -              b7  &  0.066***  &  0.075*** & -0.015***  \\
Communication -          b8  & -0.001     & -0.006*** &  0.028***  \\
Loisir/Culture -         b9  &  0.017***  &  0.030*** &  0.012***  \\
Autres biens/services -  b12 & -0.025     & -0.016    & -0.359     \\
\hline
\end{tabular}
\end{table}

\end{frame}

\end{document}

And here is a snapshot showing how the year (2000) is aligned. How can I keep the other numbers aligned but the year centered (like 2005 and 2010) ?

enter image description here

Best Answer

I'd suggest using siunitx (and booktabs for better horizontal rules).

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{siunitx,booktabs}

\begin{document}

\begin{frame}{title} 

\begin{center}
\addtolength{\tabcolsep}{-2pt} % or it would be overfull
\begin{tabular}{
  l *{3}{S[table-format=-1.3,table-space-text-post=***]}
}
\toprule
\textbf{Poste}  & {\textbf{2000}} & {\textbf{2005}} & {\textbf{2010}} \\
\midrule
Alimentation -           b1  & -0.034***  & -0.036**  & -0.016***  \\
Alcool et Tabac -        b2  & -0.009***  & -0.006    & -0.011***  \\
Habillement -            b3  &  0.004     &  0.001    &  0.001     \\
Logement -               b4  & -0.067***  & -0.106*** & -0.073***  \\
Meuble/Entretien -       b5  &  0.019***  &  0.016*** &  0.001***  \\
Santé -                  b6  & -0.001     &  0.005    &  0.036     \\
Transport -              b7  &  0.066***  &  0.075*** & -0.015***  \\
Communication -          b8  & -0.001     & -0.006*** &  0.028***  \\
Loisir/Culture -         b9  &  0.017***  &  0.030*** &  0.012***  \\
Autres biens/services -  b12 & -0.025     & -0.016    & -0.359     \\
\bottomrule
\end{tabular}
\end{center}

\end{frame}

\end{document}

As you see, in order to center a cell's contents in a numeric column, it's sufficient to type it between braces.

There's no reason for using a table environment.

enter image description here

You can certainly keep the vertical rules:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{siunitx}

\begin{document}

\begin{frame}{title} 

\begin{center}
\addtolength{\tabcolsep}{-2pt}
\begin{tabular}{
  |l| *{3}{S[table-format=-1.3,table-space-text-post=***]|}
}
\hline
\textbf{Poste}  & {\textbf{2000}} & {\textbf{2005}} & {\textbf{2010}} \\
\hline
Alimentation -           b1  & -0.034***  & -0.036**  & -0.016***  \\
Alcool et Tabac -        b2  & -0.009***  & -0.006    & -0.011***  \\
Habillement -            b3  &  0.004     &  0.001    &  0.001     \\
Logement -               b4  & -0.067***  & -0.106*** & -0.073***  \\
Meuble/Entretien -       b5  &  0.019***  &  0.016*** &  0.001***  \\
Santé -                  b6  & -0.001     &  0.005    &  0.036     \\
Transport -              b7  &  0.066***  &  0.075*** & -0.015***  \\
Communication -          b8  & -0.001     & -0.006*** &  0.028***  \\
Loisir/Culture -         b9  &  0.017***  &  0.030*** &  0.012***  \\
Autres biens/services -  b12 & -0.025     & -0.016    & -0.359     \\
\hline
\end{tabular}
\end{center}

\end{frame}

\end{document}

enter image description here

Now, compare the two renderings and take your pick. I believe you'll choose the “no vertical rule version”. ;-)