2

I have quite fine and automated (50+) tables with one problem: they do not span linewidth or textwidth respectively. I am aware of resizebox but I do not want the font size to change (it should be equal to the text).

I tried to achieve this with tabularx but it becomes difficult as the column content exceeds linewidth and siunitx is hard to reconcile with the specifics of regression tables, especially significance stars and parentheses around standard errors in the second row.


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{dcolumn}

\begin{document}
This table is not linewidth. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

\begin{table}[h!]\centering
\small
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Regression Results - Not linewidth/textwidth}
\begin{tabular}{l*{3}{D{.}{.}{-1}}}
\toprule
Dependent   &\multicolumn{1}{c}{(1)\hspace{1cm}}  &\multicolumn{1}{c}{(2)\hspace{1cm}} &\multicolumn{1}{c}{(3)}\\
variable: DepVar        &\multicolumn{1}{c}{Model1}&\multicolumn{1}{c}{Model2}&\multicolumn{1}{c}{ModelModel3}\\
\midrule
VAR$^\text{v}$ &-0.601\sym{***}&              &-0.401\sym{***}\\
        &(0.015)         &              &(0.015)         \\
Constant&-7.777\sym{***}&-8.888\sym{***}&-9.999\sym{***}\\
        &(0.999)         &(0.999)         &(0.999)         \\
Fixed Effects &  \multicolumn{1}{c}{Yes}        &  \multicolumn{1}{c}{Yes}         &   \multicolumn{1}{c}{Yes}         \\
\midrule
Adjusted R$^2$& 0.77         & 0.78         &  0.79            \\
N       &  \multicolumn{1}{c}{741}         &  \multicolumn{1}{c}{741}         &  \multicolumn{1}{c}{741}         \\
\bottomrule
\end{tabular}
    \begin{tabularx}{\textwidth}{X}
    \footnotesize{Notes: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. \sym{*} \(p<0.10\), \sym{**} \(p<0.05\), \sym{***} \(p<0.01\).}
    \end{tabularx}
\label{art1tab2-results}
\end{table}

\end{document}


This is my try with tabularx which actually makes things worse since I either receive Undefined Control Sequence warnings or not superscripted stars. In addition, column spacing looks much worse and in other cases even exceeds linewidth. I would prefer to have columns of similar or equal width and make LaTeX use the space between columns for spreading columns over the textwidth. Also, it should be as automated as possible since the number of columns changes frequently.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{siunitx}[=v2] % some issue with the newest version apparently currently going on
\sisetup{
detect-all,
    input-signs = +-,
    input-symbols = {()*},
    group-digits  = false,
        % table-space-text-pre    = (,
        % table-space-text-post   = ),
explicit-sign
}
\newcommand{\sym}[1]{\rlap{$#1$}} % entering this turns of the Undefined Control Sequence Error but leads to stars no longer being superscripted

\begin{document}

\begin{table}[h!]
% \sisetup{parse-numbers=false}
\caption{Regression Results}
\begin{tabularx}{\linewidth}{@{}l*{3}{S}@{}}
\toprule
Dependent   &\multicolumn{1}{c}{(1)\hspace{1cm}}  &\multicolumn{1}{c}{(2)\hspace{1cm}} &\multicolumn{1}{c}{(3)}\\
variable: DepVar        &\multicolumn{1}{c}{Model1}&\multicolumn{1}{c}{Model2}&\multicolumn{1}{c}{ModelModel3}\\
\midrule
VAR$^\text{1}$&-0.601\sym{***}&              &-0.401\sym{***}\\
        &(0.015)         &              &(0.015)         \\
Constant&-7.777\sym{***}&-8.888\sym{***}&-9.999\sym{***}\\
        &(0.999)         &(0.999)         &(0.999)         \\
Fixed Effects &  \multicolumn{1}{c}{Yes}        &  \multicolumn{1}{c}{Yes}         &   \multicolumn{1}{c}{Yes}         \\
\midrule
Adjusted R$^2$& 0.77         & 0.78         &  0.79            \\
N       &  \multicolumn{1}{c}{741}         &  \multicolumn{1}{c}{741}         &  \multicolumn{1}{c}{741}         \\
\bottomrule
\multicolumn{4}{@{}X}{\footnotesize{Notes: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. \sym{*} \(p<0.10\), \sym{**} \(p<0.05\), \sym{***} \(p<0.01\).}}
\end{tabularx}
\label{art1tab2-results}
\end{table}

This table is linewide but does not look nice anymore. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
\end{document}

Any help is much appreciated.

2
  • Welcome to TeX.SE.
    – Mico
    Oct 5, 2022 at 20:12
  • 2
    +1 for "I am aware of \resizebox but I do not want the font size to change" alone. :-)
    – Mico
    Oct 5, 2022 at 20:15

1 Answer 1

2

Your tabularx environments aren't full-width because you're not employing the X column type anywhere.

However, since you don't seem to need to require automatic line-breaking capabilities in any of the cells, you probably should be using a tabular* environment instead of a tabularx environment in order to obtain a table that spans the full width of the text block. See the first table below.

I'm not convinced, though, that it's a good idea to force the table to span the entire width of the textblock. In the second table below, I employ an ordinary tabular environment and embed the \caption directive, the tabular material, and the subsequent legend in a threeparttable environment. Speaking for myself, I find a compact table to be easier on the eyes than a table with huge swaths of whitespace between the columns.

enter image description here

\documentclass{article}
%%\usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage[T1]{fontenc}
\usepackage{amsmath,booktabs}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D..{#1}}

\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\usepackage{threeparttable}  % for second table

\begin{document}


\begin{table}[ht]
\setlength\tabcolsep{0pt} % let LaTeX figure out amount of intercolumn whitespace
\caption{Regression --- \texttt{tabular*}}
\label{art1tab2-results}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} l *{3}{d{2.6}} }
\toprule
Dependent          &\mc{(1)}    &\mc{(2)}    &\mc{(3)}     \\
variable: DepVar   &\mc{Model 1}&\mc{Model 2}&\mc{Model 3} \\
\midrule
VAR\textsuperscript{v} & -0.601\sym{***} & &-0.401\sym{***} \\
                       & (0.015)         & &(0.015)         \\
Constant               &-7.777\sym{***}  &-8.888\sym{***} &-9.999\sym{***}\\
                       & (0.999)         &(0.999)         &(0.999)        \\
\addlinespace
Fixed Effects  & \mc{Yes}  & \mc{Yes}  & \mc{Yes} \\
Adjusted $R^2$ & \mc{0.77} & \mc{0.78} & \mc{0.79} \\
$N$            & \mc{741}  & \mc{741}  & \mc{741} \\
\bottomrule
\end{tabular*}

\smallskip
\footnotesize Notes: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. \sym{*}~\(p<0.10\), \sym{**}~\(p<0.05\), \sym{***}~\(p<0.01\).
\end{table}



\medskip
\begin{table}[h]
\centering

\begin{threeparttable}
\caption{Regression --- \texttt{tabular/threeparttable}}
\label{art1tab2-results2}

\begin{tabular}{@{} l *{3}{d{2.6}} @{}}
\toprule
Dependent          &\mc{(1)}    &\mc{(2)}    &\mc{(3)}     \\
variable: DepVar   &\mc{Model 1}&\mc{Model 2}&\mc{Model 3} \\
\midrule
VAR\tnote{v}       & -0.601\sym{***} & &-0.401\sym{***} \\
                   & (0.015)         & &(0.015)         \\
Constant           &-7.777\sym{***}  &-8.888\sym{***} &-9.999\sym{***}\\
                   & (0.999)         &(0.999)         &(0.999)        \\
\addlinespace
Fixed Effects  & \mc{Yes}  & \mc{Yes}  & \mc{Yes} \\
Adjusted $R^2$ & \mc{0.77} & \mc{0.78} & \mc{0.79} \\
$N$            & \mc{741}  & \mc{741}  & \mc{741} \\
\bottomrule
\end{tabular}

\smallskip
\footnotesize Notes: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. \sym{*}~\(p<0.10\), \sym{**}~\(p<0.05\), \sym{***}~\(p<0.01\).

\end{threeparttable}
\end{table}

\end{document}
3
  • 1
    Thanks, very helpful answer! I totally agree, compact tables are probably more readable but if the typical table is close to textwide, your tabular* suggestion provides the solution to visual consistency.
    – Magasinus
    Oct 6, 2022 at 18:44
  • 1
    One question though: Can you elaborate on the d{2.6}? It seems that this causes some margin in my main document on the right side of the table.
    – Magasinus
    Oct 6, 2022 at 18:45
  • 1
    @Magasinus - d{2.6} tels LaTeX to "set aside enough space for 2 ordinary digits and 6 decimal digits". (- and * also take up some space.) The code in your example uses D{.}{.}{-1}, which is equivalent to d{-1}; this tells LaTeX to always place the decimal markers in the center of the column. This can create a rather asymmetrical "look" if the number of decimal digits strongly exceeds the number of ordinary digits (or vice versa). I chose d{2.6} to improve the appearance of the table at hand, not as some general law of nature (or, more particularly, design of tables).
    – Mico
    Oct 6, 2022 at 19:03

You must log in to answer this question.

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