1

I am struggling to align multicolumn objects when I have to take into account (significance) stars in my stats tables. I use the table-space-text-post ={***} command to ensure the table horizontal bars cover over the figures--otherwise the stars span out of the table's \toprule. This causes another problem, though: my headers and other text within the cells affected by table-space-text-post are not properly aligned with the stats (i.e. all which is wrapped in the \multicolumn environment). As a side note, I use the \sisetup command to ensure figures inside parentheses get aligned properly as well, which does seem to work. This is the code I have so far:

\documentclass{article}
\usepackage{booktabs,caption}
\captionsetup[table]{font=large}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\usepackage{adjustbox}
\usepackage{rotating}
\usepackage[flushleft]{threeparttable}

% *****************************************************************
% siunitx
% *****************************************************************
\usepackage{siunitx} 
\sisetup{group-separator = {,}, group-four-digits,
        detect-mode,
        tight-spacing           = true,
        input-signs             = ,
        input-symbols           = ,
        input-open-uncertainty  = ,
        input-close-uncertainty = ,
        table-align-text-pre    = false,
        table-space-text-pre    = (,
        } % centering in tables

\begin{document}

\begin{tabular}{l S[table-format=1.3, table-space-text-post ={***}]} \toprule \toprule
Text &       \mc{abc}  \\
\midrule \\
T &  0.444***   \\
& ( 0.111) \\ \addlinespace
Constant &  0.888*** \\
& ( 0.222) \\ \addlinespace
Observations & \mc{99,999} \\
R-square &  0.123 \\
\bottomrule \bottomrule
\end{tabular}
\end{document}

How can I properly align the column with text, stats, and stars? If you see the table below, which results from the code above, the header "abc" and the "99,999" figure align with the numbers and the stars together (as if the numbers and stars were one object). I would like for the header to align with the numbers only and ignore the stars. Any help would be greatly appreciated.

enter image description here

2
  • What kind of alignment do you expect? Currently, the column header seems to be horizontally centered with respect to the entries including the asterisks, which is exactly the output one would expect from the code you show.
    – leandriis
    Commented Feb 22, 2021 at 18:31
  • Thanks for the question @leandriis. I would like for the text in the heading and the "99,999" to align center with the figures as if there were no stars. Commented Feb 22, 2021 at 20:33

1 Answer 1

0

The problem is that you're using a c column, which effectively removes any ability of siunitx to deal with the number. So you need to use an S column for the multicolumn command and then fix the parameters for that S column for the odd number in the column. In this case you can specify

\multicolumn{1}{S[table-format=2]}{99999}

to get the alignment you want.

\documentclass{article}
\usepackage{booktabs,caption}
\captionsetup[table]{font=large}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

% *****************************************************************
% siunitx
% *****************************************************************
\usepackage{siunitx} 
\sisetup{group-separator = {,}, group-four-digits,
        detect-mode,
        tight-spacing           = true,
        input-signs             = ,
        input-symbols           = ,
        input-open-uncertainty  = ,
        input-close-uncertainty = ,
        table-align-text-pre    = false,
        table-space-text-pre    = (,
        } % centering in tables

\begin{document}

\begin{tabular}{l S[table-format=1.3, table-space-text-post ={***}]} \toprule \toprule
Text &       \mc{abc}  \\
\midrule \\
T &  0.444***   \\
& ( 0.111) \\ \addlinespace
Constant &  0.888*** \\
& ( 0.222) \\ \addlinespace
Observations & \multicolumn{1}{S[table-format=2]}{99999}\\
R-square &  0.123 \\
\bottomrule \bottomrule
\end{tabular}
\end{document}

output of code

2
  • Thank you @Alan Munn! That does solve the issue. Just two questions for clarity. Would I get the same result if I changed my macro \mc to say something like \newcommand\mc[1]{S[table-format=2]}? Also, how do you know that 2 is the right value for table-format? Commented Feb 24, 2021 at 11:36
  • @AlvaroGallegos Yes, of course the \mc macro can be changed (try it!). But you can't then use that version for the column heading. So you'll practically need two macros. As for the table format number, your main format for the column is 1.3, and the odd number is 5 digits so I added one to the 1.3 and removed the decimal places. So depending on what your odd numbers are in other contexts you may need to adjust the number accordingly.
    – Alan Munn
    Commented Feb 24, 2021 at 17:53

You must log in to answer this question.

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