1

I have a regression table that has three columns. One for the names, one for the estimates and one for the standard errors. The two columns that display the estimates and the standard errors are headed by the name of a variable. I align the numbers in the cells with the help of \dcolumn.

The problem is, that if there is a rather long text in a \multicolumn, it is the last column of the table that gets stretched. This problem is known and there are already solutions for that here and here.

I just don't get how I could apply them to my table with aligned columns.

Here is a MWE with vertical bars to better illustrate the widths:

\documentclass{article}

\usepackage{tabularx}
\usepackage{dcolumn}
\usepackage{booktabs}

\begin{document}
    \begin{table}[t]
        \caption{MWE}
        \centering
        \begin{tabular}{l|D{.}{.}{3}|D{.}{.}{3}}
            \toprule
            & \multicolumn{2}{c}{Long name of dependent variable} \\
            & \multicolumn{1}{c}{$\beta$} & \multicolumn{1}{c}{\textit{SE}} \\
            \midrule
            x1 & 0.020 & (0.009) \\
            x2 & -0.345 & (0.123) \\
            \bottomrule
        \end{tabular}
    \end{table}
\end{document}

The table looks like this: MWE table with different column width

What I would like to see is this alignment, equal column widths and a centered column header:

MWE table with equal columns but without variable name

...but with the variable name as in the first table.

Note: I do not insist on using \dcolumn or any other package. Everything that works (and does not potentially create issues with other basic packages) is fine.

1

With siunitx and p{...} column type for \multicolumn{2}{..}{...}:

enter image description here

\documentclass{article}

\usepackage{siunitx}
\usepackage{booktabs}

\begin{document}
    \begin{table}[t]
    \sisetup{input-symbols = (),
             table-column-width=13mm,
             table-format=-1.3}
        \caption{MWE}
        \centering
        \begin{tabular}{l SS}
            \toprule
                & \multicolumn{2}{>{\centering\arraybackslash}p{\dimexpr26mm+2\tabcolsep}}{Long name of dependent variable} \\
                & {$\beta$} & {\textit{SE}} \\
            \midrule
            x1  & 0.020     & (0.009)       \\
            x2  & -0.345    & (0.123)       \\
            \bottomrule
        \end{tabular}
    \end{table}
\end{document}
2
  • I suggest adding @{} in the start and end of the tabular preamble to remove the side bearing. – Sveinung Jul 11 '19 at 13:55
  • Thank you. This works! – ManuNeu Jul 11 '19 at 17:00
1

Since you said any packages, here is a solution using cals:

\documentclass{article}
\usepackage{cals, caption}

\let\nc=\nullcell                                  % Shortcuts
\let\sc=\spancontent

\begin{document}

\begin{table*}
\caption{MWE}
\footnotesize
\begin{calstable}[c]
% Defining columns relative to each other and relative to the margins
\colwidths{{\dimexpr(\columnwidth)/14\relax}
            {\dimexpr(\columnwidth)/9\relax}
            {\dimexpr(\columnwidth)/9\relax}
            }
% The tabular fills the text area if sum of all columns is 6

% Set up the tabular
\makeatletter
\def\cals@framers@width{0.8pt}   % Outside frame rules, reduce if the rule is too heavy
\def\cals@framecs@width{0pt}
\def\cals@bodyrs@width{0.6pt}
\def\cals@cs@width{0pt}             % Inside rules, reduce if the rule is too heavy
\def\cals@rs@width{0.6pt}
\def\cals@bgcolor{}

\def\bb{\ifx\cals@borderB\relax     % Botton border switch (off-on)
    \def\cals@borderB{0pt}
\else \let\cals@borderB\relax\fi}

\def\lp{\ifdim\cals@paddingL=0.0pt\relax    % Left padding switch (off-on)
    \cals@setpadding{Ag}
\else \setlength{\cals@paddingL}{0pt}\fi}

\def\rp{\ifdim\cals@paddingR=0.0pt\relax    % Right padding switch (off-on)
    \cals@setpadding{Ag}
\else \setlength{\cals@paddingR}{0pt}\fi}

% R1H1
\thead{%
\brow
    \bb\lp\cell{}\lp\bb
    \lp\nc{ltb}\lp
    \lp\rp\nc{rtb}\alignC\sc{Long name of dependent variable}\rp\lp
\erow
%R2H2
\brow
    \alignL\cell{}\lp
    \alignC\cell{\vfil $\beta$}
    \rp\alignC\cell{\vfil\textit{SE}}\rp\bb
\erow
}
\tfoot{\lastrule\strut}
%R3B2
\brow
    \lp\alignL\cell{\vfil X1}\lp
    \alignR\cell{\vfil 0.020}
    \rp\alignR\cell{\vfil (0.009)}\rp
\erow
%R4B3
\brow
    \bb\lp\alignL\cell{\vfil X2}\lp
    \alignR\cell{\vfil $-$0.345}
    \rp\alignR\cell{\vfil (0.123)}\rp\bb
\erow
\makeatletter
\end{calstable}\par
\end{table*}

\end{document}

enter image description here

1
  • Thank you! As you demonstrate, this works, too. I accepted the answer above just because it was simpler to implement. – ManuNeu Jul 15 '19 at 8:12

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.