如何调整我的表格尺寸以使其完全显示?

如何调整我的表格尺寸以使其完全显示?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{booktabs}
\begin{document}
\begin{center}
\begin{tabular}{lccccc}
 \hline\hline
  & \multicolumn{2}{c}{Pre-block}  & \multicolumn{2}{c}{Post-block} & Paired \textit{t}-test   \\ 
\cline{2-3} \cline{4-5} \cline{6-6}

        &  Mean   & Standard error                                                  &   Mean          
    & Standard error    & \textit{t}-stats                                                  \\    \hline
Panel A. Contributions from all contributors&            &            &            &            &            \\
Addition    &     1105.53&      225.67&      538.01&      117.00&        2.89\\
Deletion    &      528.96&      167.25&      174.57&       38.21&        2.32\\
Total       &     1634.49&      389.77&      712.58&      153.13&        2.69\\
\hline
\addlinespace[0.3cm]
Panel B. Contributions from nonblocked contributors&            &            &            &            &            \\
Addition    &     3592.67&      787.90&     1887.40&      408.73&        2.48\\
Deletion    &     1798.83&      585.61&      612.42&      133.49&        2.22\\
Total       &     5391.50&     1362.84&     2499.82&      534.91&        2.41\\

\hline

\end{tabular}
\end{center}
\end{document}

答案1

这是我的建议,\multicolumn用于“面板 A...”和“面板 B...”文本booktabs(您已经加载),用于水平线(特别是\cmidrule在相邻 s 之间添加小水平空白的命令\cmidrule)以及siunitx改进数字的对齐。为了使整个表格更窄,我缩写了术语“标准错误”。或者,您也可以将单词分成两行以节省一些水平空间:

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{makecell}
\begin{document}
\begin{center}
\begin{tabular}{l*{3}{S[table-format=4.2]} S[table-format=3.2] S[table-format=1.2]}
 \toprule
  & \multicolumn{2}{c}{Pre-block}  & \multicolumn{2}{c}{Post-block} & {Paired \textit{t}-test}   \\ 
\cmidrule(r){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-6}

            &  {Mean}    & {Std Err } &   {Mean}   & {Std Err}  & {\textit{t}-stats} \\    \midrule
\multicolumn{6}{@{}l}{Panel A. Contributions from all contributors} \\
Addition    &     1105.53&      225.67&      538.01&      117.00&        2.89\\
Deletion    &      528.96&      167.25&      174.57&       38.21&        2.32\\
Total       &     1634.49&      389.77&      712.58&      153.13&        2.69\\
\midrule
\multicolumn{6}{@{}l}{Panel B. Contributions from nonblocked contributors} \\
Addition    &     3592.67&      787.90&     1887.40&      408.73&        2.48\\
Deletion    &     1798.83&      585.61&      612.42&      133.49&        2.22\\
Total       &     5391.50&     1362.84&     2499.82&      534.91&        2.41\\

\bottomrule

\end{tabular}
\end{center}

\begin{center}
\begin{tabular}{l*{3}{S[table-format=4.2]} S[table-format=3.2] S[table-format=1.2]}
 \toprule
  & \multicolumn{2}{c}{Pre-block}  & \multicolumn{2}{c}{Post-block} & {Paired \textit{t}-test}   \\ 
\cmidrule(r){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-6}

            &  {Mean}    & {\makecell{Standard\\ error}} &   {Mean}   & {\makecell{Standard\\ error}}  & {\textit{t}-stats} \\    \midrule
\multicolumn{6}{@{}l}{Panel A. Contributions from all contributors} \\
Addition    &     1105.53&      225.67&      538.01&      117.00&        2.89\\
Deletion    &      528.96&      167.25&      174.57&       38.21&        2.32\\
Total       &     1634.49&      389.77&      712.58&      153.13&        2.69\\
\midrule
\multicolumn{6}{@{}l}{Panel B. Contributions from nonblocked contributors} \\
Addition    &     3592.67&      787.90&     1887.40&      408.73&        2.48\\
Deletion    &     1798.83&      585.61&      612.42&      133.49&        2.22\\
Total       &     5391.50&     1362.84&     2499.82&      534.91&        2.41\\

\bottomrule

\end{tabular}
\end{center}

\end{document}

答案2

通过包装器让“面板 A...”和“面板 B...”突出到其他列中,\multicolumn{6}{l}{...}可以实现大部分功能 - 比较下面表 1 和表 2 的外观。但是,仅凭这一更改并不能保证表格实际上完全适合文本块。

以下是一些额外的建议(无特定顺序):

  • 使用tabular*环境而不是tabular环境,让 LaTeX 找出允许的列间空白量。

  • 更一致地使用包的命令booktabs。到目前为止,您使用\addlinespace,但不使用\toprule\midrule\bottomrule\cmidrule。分别使用这些命令代替\hline\cline,将大大减少拥挤和幽闭恐惧症的印象。

  • 将五个数据列中的数字对齐到各自的小数列。这可以借助包S提供的列类型来完成siunitx

  • 将标题缩写Standard errorStd. error,以平衡前四个数据列的外观。

这些想法在下面表 3 中实现。

(下图中的垂直线表示文本块的边缘。)

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx,caption,booktabs}
\usepackage{siunitx}   % for 'S' column type
\usepacakge{showframe} % denote edges of textblock
\begin{document}

\begin{table}
\caption{OP's original form}
\begin{tabular}{lccccc}
\hline\hline
  & \multicolumn{2}{c}{Pre-block}  & \multicolumn{2}{c}{Post-block} & Paired \textit{t}-test   \\ 
\cline{2-3} \cline{4-5} \cline{6-6}
        &  Mean   & Standard error                                                  &   Mean          
    & Standard error    & \textit{t}-stats                                                  \\    \hline
Panel A. Contributions from all contributors&            &            &            &            &            \\
Addition    &     1105.53&      225.67&      538.01&      117.00&        2.89\\
Deletion    &      528.96&      167.25&      174.57&       38.21&        2.32\\
Total       &     1634.49&      389.77&      712.58&      153.13&        2.69\\
\hline
\addlinespace[0.3cm]
Panel B. Contributions from nonblocked contributors&            &            &            &            &            \\
Addition    &     3592.67&      787.90&     1887.40&      408.73&        2.48\\
Deletion    &     1798.83&      585.61&      612.42&      133.49&        2.22\\
Total       &     5391.50&     1362.84&     2499.82&      534.91&        2.41\\
\hline
\end{tabular}

\vspace{1cm}
\caption{Let header lines protrude out of column 1}
\begin{tabular}{lccccc}
\hline\hline
  & \multicolumn{2}{c}{Pre-block}  & \multicolumn{2}{c}{Post-block} & Paired \textit{t}-test   \\ 
\cline{2-3} \cline{4-5} \cline{6-6}
        &  Mean   & Standard error                                                  &   Mean          
    & Standard error    & \textit{t}-stats                                                  \\    \hline
\multicolumn{6}{l}{Panel A. Contributions from all contributors} \\
Addition    &     1105.53&      225.67&      538.01&      117.00&        2.89\\
Deletion    &      528.96&      167.25&      174.57&       38.21&        2.32\\
Total       &     1634.49&      389.77&      712.58&      153.13&        2.69\\
\hline
\addlinespace[0.3cm]
\multicolumn{6}{l}{Panel B. Contributions from nonblocked contributors} \\
Addition    &     3592.67&      787.90&     1887.40&      408.73&        2.48\\
Deletion    &     1798.83&      585.61&      612.42&      133.49&        2.22\\
Total       &     5391.50&     1362.84&     2499.82&      534.91&        2.41\\
\hline
\end{tabular}

\vspace{1cm}
\caption{Further improvements}
\setlength\tabcolsep{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
  l *{3}{S[table-format=4.2]} 
         S[table-format=3.2]
         S[table-format=1.2] }
\toprule
& \multicolumn{2}{c}{Pre-block}  
& \multicolumn{2}{c}{Post-block} 
& {Paired $t$-test}   \\ 
\cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-6}
& {Mean} & {Std.\ error} & {Mean} & {Std.\ error} & {$t$-stats} \\
\midrule
\multicolumn{6}{l}{Panel A\@. Contributions from all contributors}  \\
Addition    &     1105.53&      225.67&      538.01&      117.00&        2.89\\
Deletion    &      528.96&      167.25&      174.57&       38.21&        2.32\\
Total       &     1634.49&      389.77&      712.58&      153.13&        2.69\\
\addlinespace[0.3cm]
\multicolumn{6}{l}{Panel B\@. Contributions from nonblocked contributors} \\
Addition    &     3592.67&      787.90&     1887.40&      408.73&        2.48\\
Deletion    &     1798.83&      585.61&      612.42&      133.49&        2.22\\
Total       &     5391.50&     1362.84&     2499.82&      534.91&        2.41\\
\bottomrule
\end{tabular*}

\end{table}
\end{document}

相关内容