6

I use siunitx to decimal align the contents of tables that I create with Stata's estout, as shown in the MWE below. I think the output is perfect, with the numbers being aligned on the decimal point and "pseudo"-centered under the "ß / SE" and "Margin" columns.

The problem is that I get an overfull hbox warning for every single cell. I've played around with table-space-text-post to include the asterisk, but without any luck. Does anyone have a solution for this problem?

\documentclass{scrartcl}

\usepackage{lmodern}

\newcommand{\sym}[1]{\rlap{#1}}

\usepackage{siunitx}
\sisetup{
        detect-mode,
        tight-spacing               = true,
        group-digits                = false ,
        input-signs             = ,
        input-symbols               = ( ) - + *,
        input-open-uncertainty  = ,
        input-close-uncertainty = ,
        table-align-text-post   = false,
        % table-space-text-pre  = -,
        % table-space-text-post = *
        }

\usepackage{booktabs}

\begin{document}
\begin{tabular*}
{\textwidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{3}{S[table-format=1.3,table-column-width=11mm]S[table-format=1.3,table-column-width=11mm]}}
\toprule
&\multicolumn{2}{c}{(1)}                    &\multicolumn{2}{c}{(2)}                    &\multicolumn{2}{c}{(3)}                    \\
&\multicolumn{2}{c}{Column One}              &\multicolumn{2}{c}{Column Two X}&\multicolumn{2}{c}{Column Three XX}\\
&\multicolumn{1}{c}{$\beta$ / SE}         &\multicolumn{1}{c}{Margin}         &\multicolumn{1}{c}{$\beta$ / SE}         &\multicolumn{1}{c}{Margin}         &\multicolumn{1}{c}{$\beta$ / SE}         &\multicolumn{1}{c}{Margin}         \\
\midrule
\hspace{0.1cm} 18--24&      -0.176         &      -0.044         &      -0.256         &      -0.047         &      -0.820\sym{***}&      -0.101\sym{***}\\
                    &     (0.152)         &                     &     (0.188)         &                     &     (0.310)         &                     \\
\hspace{0.1cm} 25--34&       0.067         &       0.017         &       0.047         &       0.009         &      -0.046         &      -0.006         \\
\bottomrule
\addlinespace[.75ex]
\end{tabular*}
\end{document}

1 Answer 1

7

If you want to have space reserved for something after the number part in an S column, you will need to reserve appropriate space using table-space-text-post. A slight awkwardness arises as the array package treats * as 'special', so you need braces here:

\documentclass{article}

\usepackage{siunitx}

\begin{document}
\begin{tabular}{S[ table-format = -1.3, table-space-text-post = {***}]}
  -0.101***
\end{tabular}

\end{document}

If you are using a custom command (here \sym) in an S column, it really needs to be engine-protected. For that, the \NewDocumentCommand command from xparse is recommended:

\documentclass{article}

\usepackage{siunitx}

\NewDocumentCommand{\sym}{m}{#1}

\begin{document}
\begin{tabular}{S[table-format = -1.3, table-space-text-post = \sym{***}]}
  -0.101\sym{***}
\end{tabular}

\end{document}
5
  • Thanks, but if I use that on my MWE I still get 3 overfull hboxes because of the parentheses. If I remove them, the warning disappear. input-symbols = ( ) should be correct command to include parentheses, right?
    – Jörg
    Commented May 31, 2012 at 10:21
  • @Jörg I was trying to focus the answer of the point in hand (dealing with * as a suffix), so my demo does not cover the other parts of your MWE. As you say, you will need to add the appropriate input-symbols for parentheses: these also need to be allowed for in the table-format (each one requires space for an additional 'digit'). That might make a good, focussed, follow-up question.
    – Joseph Wright
    Commented May 31, 2012 at 10:24
  • Okay, that answers my problem then. My initial question was not focussed solely on the *, but on avoiding the hbox warnings. I did not know that one needs to include extra space for the parentheses, so thank you for the clarification.
    – Jörg
    Commented May 31, 2012 at 10:29
  • @JosephWright If I understand this correctly this will align the ** below each other even if a number has less decimals than specified with table-format. Is there a way to get the stars left-aligned to the numbers in any case?
    – cgnieder
    Commented Jul 16, 2014 at 18:05
  • @cgnieder Set table-align-text-post = false
    – Joseph Wright
    Commented Jul 16, 2014 at 19:51

You must log in to answer this question.

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