我有非常精细和自动化的 (50+) 表格,但有一个问题:它们不分别跨越linewidth
。textwidth
我知道resizebox
但我不想改变字体大小(它应该等于文本)。
我尝试过实现这一点,tabularx
但由于列内容超出范围linewidth
,并且siunitx
难以与回归表的细节相协调,尤其是第二行标准误差周围的显著性星号和括号,因此变得很困难。
\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}
这是我尝试过的,但tabularx
实际上情况更糟,因为我要么收到Undefined Control Sequence
警告,要么没有上标星号。此外,列间距看起来更糟,有时甚至超过linewidth
。我更希望列的宽度相似或相等,并让 LaTeX 使用列之间的空间来扩展列textwidth
。此外,它应该尽可能自动化,因为列数经常变化。
\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}
任何帮助深表感谢。
答案1
您的tabularx
环境不是全宽的,因为您没有X
在任何地方使用列类型。
但是,由于您似乎不需要在任何单元格中要求自动换行功能,因此您可能应该使用环境tabular*
而不是环境tabularx
来获得跨越整个文本块宽度的表格。 请参阅下面的第一个表格。
不过,我并不认为强制表格横跨整个文本块的宽度是个好主意。在下面的第二个表格中,我使用了一个普通tabular
环境,并将\caption
指令、tabular
材料和后续图例嵌入到三部分表环境。就我个人而言,我发现紧凑的表格比列之间有大量空白的表格更容易让人看清。
\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}