10

I would love to align the columns (containing the numbers) on the decimal point. I have been reading about the package 'siuntix', but this fails to correctly incorporate the numbers in the parentheses below, and the asterisk is also hard to deal with.

Does anyone knows how to align the numbers in the table below?

Thank you very much!

\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{l c c c c}
\hline
    & $\beta_1$ & $\beta_2$ & $\beta_2$ & $\beta_4$ \\ \hline
XXX & 1.23      & 0.23$^*$    & -1.23      & 2.41$^*$      \\
XXX & (-1.39)    & (4.23)   & (4.21)    & (-2.92)    \\
XXX & 2.51      & 2.66      & 0.25      & 1.52      \\
XXX & (2.11)    & (4.11)    & (-2.45)    & (5.21)    \\
XXX & 1.67$^*$      & -3.15      & 0.82      & 1.11$^*$      \\
XXX & (1.23)    & (-3.11)    & (2.11)    & (4.11)    \\ \hline
\end{tabular}
\end{table}
15

If all you need to achieve is to align the numbers on their decimal markers, using the siunitx package may be a bit of overkill. The dcolumn package will let you achieve your objective as well.

enter image description here

\documentclass{article}

\usepackage{dcolumn,booktabs}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\begin{document}

\begin{table}
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{l *{4}{d{3.3}} }
\toprule
& \mc{$\beta_1$} & \mc{$\beta_2$} & \mc{$\beta_2$} & \mc{$\beta_4$} \\ 
\midrule
XXX &   1.23    &   0.23^*  &  -1.23    &   2.41^* \\
XXX & (-1.39)   &  (4.23)   &  (4.21)   & (-2.92)  \\ \addlinespace
XXX &   2.51    &   2.66    &   0.25    &   1.52   \\
XXX &  (2.11)   &  (4.11)   & (-2.45)   &  (5.21)  \\ \addlinespace
XXX &  1.67^*   &  -3.15    &   0.82    &   1.11^* \\
XXX & (1.23)    & (-3.11)   &  (2.11)   &  (4.11)  \\ 
\bottomrule
\end{tabular}
\end{table}

\end{document}
  • Thanks a lot for your fast reply! Is it maybe possible to shrink the space in between the columns and still remain the beta (header of the column) in the middle of the column? Later on I am having larger tables and they are not fitting the page. Also, just applying \small is not enough. Thanks in advance! – Stefan Jun 12 '17 at 20:24
  • @Stefan - The amount of inter-column whitespace is governed by the length parameter \tabcolsep; its default value is 6pt in most document classes. You could try issuing the instruction \setlength\tabcolsep{3pt} immediately before \begin{tabular}{....} and see if that helps. – Mico Jun 12 '17 at 20:29
  • +1. Nice answer. It seems tex.stackexchange doesn't render LaTeX as, for example, math.stackexchange do. That's awful !!!. – Felix Marin Jun 13 '17 at 1:02
  • @FelixMarin - I hate to have to contradict you outright, but I believe it's required here. The main purpose of TeX.SE is to develop and offer solutions to typesetting issues by analyzing and improving TeX and LaTeX code. MathJax is disabled intentionally on TeX.SE: people actually want to see the code, not the output generated by MathJax. Hence, the setup is not awful at all... – Mico Jun 13 '17 at 5:59
  • @Mico, I just tried to write a similar table with siunitx, but I failed. reports error: "misplaced-sign-token" (caused with (-3.11)). so it looks like the tables in your answer can not be written with siunitx. +1 for nice answer! – Zarko May 31 '18 at 17:45

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.