5

I have a problem with the alignment of the commas in a regression table. Due to the fact that I also have mathematical expressions in the heading, other solutions I found do not work. Is it still possible to get the commas in a row here? Here is a minimal example (I use LuaLaTeX):

\documentclass[12pt]{scrartcl}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{unicode-math}
\usepackage{booktabs}
\usepackage{array}
\usepackage{threeparttable}
\usepackage{tabularx}

\begin{document}

\begin{table}[h]
\begin{center}
\caption{Table}
\begin{threeparttable}
\begin{tabularx}{0.7\textwidth}{@{}>{$}X<{$}>{$}c<{$}>{$}c<{$}>{$}c<{$}@{}}\\
\toprule
& (\text{minw} - p50) & (\text{minw} - p50)^2 & R^2\\
\midrule
p5 - p50 & 1{,}106^{***} & 0{,}375^{***} & 0{,}441\\
& (0{,}100) & (0{,}085) &\\
p10 - p50 & 1{,}161^{***} & 0{,}516^{***} & 0{,}575\\
& (0{,}089) & (0{,}079) &\\
\bottomrule
\end{tabularx}
\begin{tablenotes}[flushleft]
\setlength\labelsep{0pt} %So that the word „Notes“ is on the left margin
\footnotesize
\item[]Notes
\end{tablenotes}
\end{threeparttable}
\end{center}
\end{table}

\end{document}

The output is here: enter image description here

2 Answers 2

2

My main recommendation would be that you employ the dcolumn package and its D column type instead of the c column type to align the numbers on their respective decimal markers (the commas, which no longer need to be encased in curly braces) in the three data columns. A second recommendation would be to place the \caption directive inside the threeparttable environment and to omit the \\ directive immediately after the start of the tabularx environment. Third, don't use a center environment inside a table environment; instead, use a \centering command.

enter image description here

\documentclass[12pt]{scrartcl}
%\usepackage{amsmath} % 'amsmath' is loaded automatically by 'mathtools'
\usepackage{mathtools}
\usepackage{unicode-math}
\usepackage{booktabs}
%\usepackage{array} % 'array' is loaded automatically by 'tabularx'
\usepackage{threeparttable}
\usepackage{tabularx}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D,,{#1}} % perform alignment on commas
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\begin{document}

\begin{table}[ht]
\centering % not '\begin{center}'
\begin{threeparttable}
\caption{Table} % \caption directive should be part of 'threeparttable' env.
\begin{tabularx}{0.7\textwidth}{@{} >{$}X<{$} *{2}{d{2.5}} d{1.3} @{}}
\toprule
& \mc{$(\textrm{minw} - p50)$} 
  & \mc{$(\textrm{minw} - p50)^2$} 
    & \multicolumn{1}{c@{}}{$R^2$} \\
\midrule
p5 - p50  & 1,106^{***} & 0,375^{***} & 0,441 \\
          & (0,100)     & (0,085) \\
p10 - p50 & 1,161^{***} & 0,516^{***} & 0,575 \\
          & (0,089)     & (0,079) \\
\bottomrule
\end{tabularx}

\smallskip\footnotesize
\begin{tablenotes}[flushleft]
\setlength\labelsep{0pt} %So that the word „Notes“ is on the left margin
\item[]Notes 
\end{tablenotes}

\end{threeparttable}
%\end{center}
\end{table}

\end{document}
2
  • Thanks, it worked! Thanks also for the explanations about unnecessary packages and other improvements. I like to learn more! However, I still do not understand 100 % why exactly. But I’ll have a look at the documentation! One more question: Should I also use \centering for graphics (\begin{figure})?
    – herry.23
    Sep 24, 2023 at 11:17
  • 1
    @herry.23 - Yes, I would use \centering rather than \begin{center}/\end{center} in both figure and table environments.
    – Mico
    Sep 24, 2023 at 11:23
2

You can try to use \mathrlap.

\documentclass[12pt]{scrartcl}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{unicode-math}
\usepackage{booktabs}
\usepackage{array}
\usepackage{threeparttable}
\usepackage{tabularx}

\begin{document}

\begin{table}[h]
\begin{center}
\caption{Table}
\begin{threeparttable}
\begin{tabularx}{0.7\textwidth}{@{}>{$}X<{$}>{$}c<{$}>{$}c<{$}>{$}c<{$}@{}}\\
\toprule
& (\text{minw} - p50) & (\text{minw} - p50)^2 & R^2\\
\midrule
p5 - p50 & 1{,}106\mathrlap{^{***}} & 0{,}375\mathrlap{^{***}} & 0{,}441\\
& (0{,}100) & (0{,}085) &\\
p10 - p50 & 1{,}161\mathrlap{^{***}} & 0{,}516\mathrlap{^{***}} & 0{,}575\\
& (0{,}089) & (0{,}079) &\\
\bottomrule
\end{tabularx}
\begin{tablenotes}[flushleft]
\setlength\labelsep{0pt} %So that the word „Notes“ is on the left margin
\footnotesize
\item[]Notes
\end{tablenotes}
\end{threeparttable}
\end{center}
\end{table}

\end{document}

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .