![忽略太宽表格的边距](https://linux22.com/image/395119/%E5%BF%BD%E7%95%A5%E5%A4%AA%E5%AE%BD%E8%A1%A8%E6%A0%BC%E7%9A%84%E8%BE%B9%E8%B7%9D.png)
我有一个相当大的表格,它超出了右边距,但与左侧对齐。相反,我希望它在页面上居中,忽略我为文档指定的文本边距。
我知道这是一个常见的问题,并且我尝试了几个小时的几种解决方案,但无论是\makebox
解决方法还是尝试暂时调整边距\adjustmargins
对我来说都不起作用。
我知道这里肯定遗漏了一些东西,但我就是找不到。
以下是我的代码的最小可重现示例:
\documentclass[a4paper,12pt]{article}
\usepackage{lipsum}
\usepackage{geometry}
\geometry{a4paper, left=3cm, top=3cm, bottom=3cm, right=3cm}
\usepackage{booktabs}
\usepackage{pdfpages}
\usepackage[labelfont = sc]{caption}
\DeclareCaptionFormat{mycaptionfont}{\fontsize{12}{13}\selectfont#1#2#3}
\captionsetup{format=mycaptionfont}
\usepackage{threeparttable}
\usepackage{graphicx}
\begin{document}
\begin{table}
\begin{threeparttable}
\captionsetup{font=large}
\caption{\textsc{Caption here}}
\label{table:1}
\scriptsize
\begin{tabular}{lcccccccccc}
\toprule
\addlinespace[0.7em]
& \multicolumn{2}{c}{log [var1111122222} & \multicolumn{2}{c}{var21111111} & \multicolumn{2}{c}{var3} & \multicolumn{2}{c}{var422222222} & \multicolumn{2}{c}{var566666666} \\
\cmidrule(lr){2-3}
\cmidrule(lr){4-5}
\cmidrule(lr){6-7}
\cmidrule(lr){8-9}
\cmidrule(lr){10-11}
& (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) & (9) & (10) \\
\midrule
& & & & & & & & & & \\
\addlinespace[0.5em]
Patient & 8.48*** & 4.86*** & 12.84*** & 9.84** & 5.11*** & 2.78 & -0.99*** & -0.50*** & 7.98 & -3.24 \\
& (1.97) & (1.48) & (3.63) & (3.78) & (1.71) & (1.76) & (0.21) & (0.18) & (7.83) & (7.14) \\
\addlinespace[0.5em]
Retaliative & 1.71 & -0.53 & 2.50 & 5.31 & 7.12** & 7.29** & -0.27 & -0.19 & -7.29 & -7.48 \\
& (3.80) & (2.85) & (6.66) & (6.40) & (3.48) & (3.40) & (0.46) & (0.34) & (16.67) & (12.86) \\
\addlinespace[0.5em]
Pro-Social & 2.43 & -0.07 & 7.05* & 6.71 & 2.55 & 2.01 & -0.28 & -0.06 & -13.14 & -17.54** \\
& (2.37) & (1.98) & (4.02) & (4.47) & (2.07) & (2.08) & (0.27) & (0.19) & (9.75) & (7.97) \\
\addlinespace[0.5em]
Constant & 5.42*** & 7.28*** & 1.04 & 0.52 & -1.11 & -1.40 & 0.69*** & 0.47** & 7.85 & 16.20** \\
& (1.58) & (1.88) & (2.76) & (3.30) & (1.36) & (2.07) & (0.17) & (0.20) & (6.15) & (7.38) \\
\addlinespace[0.5em]
Controls & No & Yes & No & Yes & No & Yes & No & Yes & No & Yes \\
& & & & & & & & & & \\
Observations & 76 & 73 & 64 & 61 & 76 & 73 & 75 & 72 & 75 & 73 \\
Adjusted R\textsuperscript{2} & 0.45 & 0.67 & 0.30 & 0.37 & 0.11 & 0.21 & 0.41 & 0.65 & 0.15 & 0.43 \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\tiny
\item\textit{Notes:} OLS estimates, robust standard errors in parentheses.*** p$<$0.01, ** p$<$0.05, * p$<$0.1
\end{tablenotes}
\end{threeparttable}
\end{table}
\lipsum[1]
\end{document}
答案1
第一种方法:如果列数较多,可以减小 的值\tabcolsep
(默认为 6pt)。这里一共有 11 列,设置为 $4pt 就足够了,因为这样可以节省 22×2pt=44pt(将近 8mm),而且表格的宽度不会比 \textwidth 宽太多。你也可以调整字体大小来节省更多空间。
第二种方法:您可以使用adjustwidth
环境,从changepage
本地获得较小的边距:
\documentclass[a4paper,12pt]{article}
\usepackage{lipsum}
\usepackage{geometry}
\geometry{a4paper, left=3cm, top=3cm, bottom=3cm, right=3cm}
\usepackage{booktabs}
\usepackage{changepage}
\usepackage{pdfpages}
\usepackage[labelfont = sc]{caption}
\DeclareCaptionFormat{mycaptionfont}{\fontsize{12}{13}\selectfont#1#2#3}
\captionsetup{format=mycaptionfont}
\usepackage{threeparttable}
\usepackage{graphicx}
\begin{document}
\begin{table}
\begin{adjustwidth}{-1cm}{-1cm}
\centering
\begin{threeparttable}
\captionsetup{font=large}
\caption{\textsc{Caption here}}
\label{table:1}
\scriptsize
\begin{tabular}{l*{10}{c}}
\toprule
\addlinespace[0.7em]
& \multicolumn{2}{c}{log [var1111122222} & \multicolumn{2}{c}{var21111111} & \multicolumn{2}{c}{var3} & \multicolumn{2}{c}{var422222222} & \multicolumn{2}{c}{var566666666} \\
\cmidrule(lr){2-3}
\cmidrule(lr){4-5}
\cmidrule(lr){6-7}
\cmidrule(lr){8-9}
\cmidrule(lr){10-11}
& (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) & (9) & (10) \\
\midrule
& & & & & & & & & & \\
\addlinespace[0.5em]
Patient & 8.48*** & 4.86*** & 12.84*** & 9.84** & 5.11*** & 2.78 & -0.99*** & -0.50*** & 7.98 & -3.24 \\
& (1.97) & (1.48) & (3.63) & (3.78) & (1.71) & (1.76) & (0.21) & (0.18) & (7.83) & (7.14) \\
\addlinespace[0.5em]
Retaliative & 1.71 & -0.53 & 2.50 & 5.31 & 7.12** & 7.29** & -0.27 & -0.19 & -7.29 & -7.48 \\
& (3.80) & (2.85) & (6.66) & (6.40) & (3.48) & (3.40) & (0.46) & (0.34) & (16.67) & (12.86) \\
\addlinespace[0.5em]
Pro-Social & 2.43 & -0.07 & 7.05* & 6.71 & 2.55 & 2.01 & -0.28 & -0.06 & -13.14 & -17.54** \\
& (2.37) & (1.98) & (4.02) & (4.47) & (2.07) & (2.08) & (0.27) & (0.19) & (9.75) & (7.97) \\
\addlinespace[0.5em]
Constant & 5.42*** & 7.28*** & 1.04 & 0.52 & -1.11 & -1.40 & 0.69*** & 0.47** & 7.85 & 16.20** \\
& (1.58) & (1.88) & (2.76) & (3.30) & (1.36) & (2.07) & (0.17) & (0.20) & (6.15) & (7.38) \\
\addlinespace[0.5em]
Controls & No & Yes & No & Yes & No & Yes & No & Yes & No & Yes \\
& & & & & & & & & & \\
Observations & 76 & 73 & 64 & 61 & 76 & 73 & 75 & 72 & 75 & 73 \\
Adjusted R\textsuperscript{2} & 0.45 & 0.67 & 0.30 & 0.37 & 0.11 & 0.21 & 0.41 & 0.65 & 0.15 & 0.43 \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\tiny
\item\textit{Notes:} OLS estimates, robust standard errors in parentheses.*** p$<$0.01, ** p$<$0.05, * p$<$0.1
\end{tablenotes}
\end{threeparttable}
\end{adjustwidth}
\end{table}
\lipsum[1]
\end{document}
答案2
通过\small
字体大小、宏\adjustwidth
的使用@{\extracolsep{\fill}}˙
以及S
列类型的使用我得到了:
(红线表示页面布局)
\documentclass[a4paper,12pt]{article}
\usepackage{geometry}
\geometry{a4paper, margin=3cm}
\usepackage{graphicx}
\usepackage[labelfont=sc]{caption}
\DeclareCaptionFormat{mycaptionfont}{\fontsize{12}{13}\selectfont#1#2#3}
\captionsetup{format=mycaptionfont}
\usepackage{booktabs}
\usepackage[referable]{threeparttablex}
\newcommand\mcc[1]{\multicolumn{2}{c}{#1}}
\usepackage{siunitx}
\usepackage{changepage}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\begin{document}
\begin{table}
\begin{adjustwidth}{-3em}{-3em}
\centering
\begin{threeparttable}
\captionsetup{font=large}
\caption{\textsc{Caption here}}
\label{table:1}
\small
\setlength\tabcolsep{0pt}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}
l *{10}{S[ table-format=2.2,
input-symbols={( )},
table-space-text-post={***}
]} }
\toprule
& \mcc{log[var1111122222]}
& \mcc{var21111111}
& \mcc{var3}
& \mcc{var422222222}
& \mcc{var566666666} \\
\cmidrule(lr){2-3}
\cmidrule(lr){4-5}
\cmidrule(lr){6-7}
\cmidrule(lr){8-9}
\cmidrule(lr){10-11}
& {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} & {(7)} & {(8)} & {(9)} & {(10)} \\
\midrule
& & & & & & & & & & \\
\addlinespace
Patient & 8.48*** & 4.86*** & 12.84*** & 9.84** & 5.11*** & 2.78 & -0.99*** & -0.50*** & 7.98 & -3.24 \\
& (1.97) & (1.48) & (3.63) & (3.78) & (1.71) & (1.76) & (0.21) & (0.18) & (7.83) & (7.14) \\
\addlinespace
Retaliative & 1.71 & -0.53 & 2.50 & 5.31 & 7.12** & 7.29** & -0.27 & -0.19 & -7.29 & -7.48 \\
& (3.80) & (2.85) & (6.66) & (6.40) & (3.48) & (3.40) & (0.46) & (0.34) & (16.67) & (12.86) \\
\addlinespace
Pro-Social & 2.43 & -0.07 & 7.05* & 6.71 & 2.55 & 2.01 & -0.28 & -0.06 & -13.14 & -17.54** \\
& (2.37) & (1.98) & (4.02) & (4.47) & (2.07) & (2.08) & (0.27) & (0.19) & (9.75) & (7.97) \\
\addlinespace
Constant & 5.42*** & 7.28*** & 1.04 & 0.52 & -1.11 & -1.40 & 0.69*** & 0.47** & 7.85 & 16.20** \\
& (1.58) & (1.88) & (2.76) & (3.30) & (1.36) & (2.07) & (0.17) & (0.20) & (6.15) & (7.38) \\
\addlinespace
Controls & {No} & {Yes} & {No} & {Yes} & {No} & {Yes} & {No} & {Yes} & {No} & {Yes} \\
& & & & & & & & & & \\
Observations & 76 & 73 & 64 & 61 & 76 & 73 & 75 & 72 & 75 & 73 \\
Adjusted R\textsuperscript{2} & 0.45 & 0.67 & 0.30 & 0.37 & 0.11 & 0.21 & 0.41 & 0.65 & 0.15 & 0.43 \\
\bottomrule
\end{tabular*}
\begin{tablenotes}[para, flushleft]\footnotesize
\note{OLS estimates, robust standard errors in parentheses.}
\item[***] p$<$0.01,
\item[** ] p$<$0.05,
\item[* ] p$<$0.1
\end{tablenotes}
\end{threeparttable}
\end{adjustwidth}
\end{table}