2

I am trying to align the values in the following regression output table by the 1000-euro-mark (the comma). However, there are also values below 1000 euros which are not aligned as I would like them to be (to the right of the commas above and below them). Is there a way to align them together with the rest despite those values lacking a comma?

\documentclass[12pt]{article}
\usepackage{booktabs, caption, dcolumn}
\newcolumntype{d}[1]{D{,}{,}{#1}}

\begin{document}

\begin{table} \centering
\caption{Regression Results}
\begin{tabular}{l*{2}{d{3.6}} }
\toprule
\multicolumn{1}{l}{Groups}   & \multicolumn{1}{c}{$1^{st}$} & \multicolumn{1}{c}{$1^{st}$} \\
\midrule
Intercept       & -32,332       & -66,459^{***} \\
                & (17,820)      & (21,006) \\ 
Income          & 340           & 870^{*} \\
                & (240)         & (340) \\
Experience      & 747^{*}       & 818 \\
                & (372)         & (469) \\
HH Type         & 5,984         & 24,189 \\
                & (12,499)      & (15,894) \\
\midrule
\multicolumn{1}{l}{R$^{2}$}     & \multicolumn{1}{c}{0.07}    & \multicolumn{1}{c}{0.20} \\
\multicolumn{1}{l}{N}         & \multicolumn{1}{c}{299}     & \multicolumn{1}{c}{299} \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

enter image description here

  • 2
    Welcome to TeX.SE. Your write-up is not perfectly clear. Please clarify the purpose of the comma symbol: is it a decimal marker or a thousands-separator? If it’s intended to be the latter, you’d be misusing the machinery of the dcolumn package. Please advise. – Mico Jul 29 at 15:59
  • From "by the 1000-euro-mark" I deduce that the comma is a thousands-separator. To achieve the desired alignment, you might want to use the siunitx package. – leandriis Jul 29 at 17:43
2

Here is my suggestion using the siunitx package in order to align the numbers:

enter image description here

\documentclass[12pt]{article}
\usepackage{booktabs, caption, dcolumn}
\newcolumntype{d}[1]{D{,}{,}{#1}}
\usepackage{siunitx}

\sisetup{
    group-digits             = true,
    group-minimum-digits     = 4,
    group-separator          = {,},
    table-align-text-pre     = false,
    table-align-text-post    = false,
    input-open-uncertainty   = ,
    input-close-uncertainty  = ,
    table-space-text-post    = $^{***}$,
    table-space-text-pre     = {(},
}
\begin{document}


\begin{table} \centering
\caption{Regression Results}
\begin{tabular}{l*{2}{S[table-format=-5]} }
\toprule
Groups          & {$1^{st}$}   & {$1^{st}$} \\
\midrule
Intercept       & -32332       & -66459$^{***}$ \\
                & (17820)      & (21006) \\ 
Income          & 340          & 870$^{*}$\\
                & (240)        & (340) \\
Experience      & 747$^{*}$    & 818 \\
                & (372)        & (469) \\
HH Type         & 5984         & 24189 \\
                & (12499)      & (15894) \\
\midrule
R$^{2}$         & {0.07}       & {0.20}\\
N               & {299}        & {299} \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

Please note that I manuallr removed the thousand separators in the numbers in the table. If you want to keep them in your code, you might want to add input-ignore={,},input-decimal-markers={.} to the \sisetup command.

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.