excel2latex 表:输出页面外的数据

excel2latex 表:输出页面外的数据

我使用插件为表格生成了以下代码excel2latex。但是在 PDF 输出中,表格很丑陋,而且大部分被截断了一半并向右移动。请提出解决方案。

% Table generated by Excel2LaTeX from sheet 'Sheet4'
\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabular}{rrrr}
\toprule
\multicolumn{1}{c}{Question 5} & \multicolumn{1}{c}{ATT} & \multicolumn{1}{c}{ATNT} & ATE \\
\midrule
      &       &       &  \\
(a) True treatment parameters & 0.471 & 0.315 & 0.365866 \\
      &       &       &  \\
(b) Kernel matching estimate & 0.546 & 0.394 & 0.443377 \\
(Variability of estimation of pscores not taken into account) &       &       &  \\
      &       &       &  \\
(c) Nearest-neighbour matching estimates & 0.448 & 0.375 & 0.398856 \\
      &       &       &  \\
(d) Treatment estimates using OLS & 0.489096 & 0.489096 & 0.489096 \\
Homogenous returns on trimmed data and specification of pscores as in Q 1 (b) &       &       &  \\
      &       &       &  \\
(e) Treatment estimates using Linear Regression & 0.587089 & 0.378109 & 0.44625 \\
      &       &       &  \\
(f) Treatment estimates using Re-weighting & 0.556587 & 0.417025 & 0.462531 \\
\bottomrule
\end{tabular}%
\label{tab:addlabel}%
\end{table}%

答案1

使此表适合页边距的最简单方法是使用tabularx。这要求您使用tabularx环境(而不是tabular)并指定表格的宽度(\linewidth将拉伸整个文本块宽度)。

这是你的表格,包含在一个最小的工作示例中(取消注释showframe包裹查看文本块边界):

在此处输入图片描述

\documentclass{article}
%\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}

% Table generated by Excel2LaTeX from sheet 'Sheet4'
\begin{table}[htbp]
  \centering
  \caption{Add caption}
  \begin{tabularx}{\textwidth}{>{\raggedleft\arraybackslash}Xrrr}
    \toprule
    \multicolumn{1}{c}{Question 5} & \multicolumn{1}{c}{ATT} & \multicolumn{1}{c}{ATNT} & ATE \\
    \midrule
      &       &       &  \\
      (a) True treatment parameters & 0.471 & 0.315 & 0.365866 \\
      &       &       &  \\
      (b) Kernel matching estimate & 0.546 & 0.394 & 0.443377 \\
      (Variability of estimation of pscores not taken into account) &       &       &  \\
      &       &       &  \\
      (c) Nearest-neighbour matching estimates & 0.448 & 0.375 & 0.398856 \\
      &       &       &  \\
      (d) Treatment estimates using OLS & 0.489096 & 0.489096 & 0.489096 \\
      Homogenous returns on trimmed data and specification of pscores as in Q 1 (b) &       &       &  \\
      &       &       &  \\
      (e) Treatment estimates using Linear Regression & 0.587089 & 0.378109 & 0.44625 \\
      &       &       &  \\
      (f) Treatment estimates using Re-weighting & 0.556587 & 0.417025 & 0.462531 \\
    \bottomrule
  \end{tabularx}%
  \label{tab:addlabel}%
\end{table}%
\end{document}

tabularx提供一种X列类型,可根据需要填充文本块的剩余部分,以填充到第二个参数中指定的宽度tabularxarray包裹X符号允许您在每个列条目之前插入内容:>{\raggedleft\arraybackslash}允许右对齐/左对齐,同时恢复新行\arraybackslash的传统用法。\\tabular

如果你不感兴趣tabularx,你也可以使用

\begin{tabular}{>{\raggedleft\arraybackslash}p{.5\linewidth}rrr}
%...
\end{tabular}%

此处的p{<len>}列创建了一个p宽度为 的 aragraph-style 列<len>,从而强制条目在必要时换行。这允许您根据自己的喜好缩小表格的宽度。

答案2

每行的第一个单元格总是相同大小。第一个单元格中的文本非常长,至少在某些行中如此。一种可能的解决方案是将这些行设为多列,参见下面的示例。无论如何,如果您想要一个更漂亮的表格,您将不得不重新安排一些东西。

\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabular}{lrrr}
\toprule
\multicolumn{1}{c}{Question 5} & \multicolumn{1}{c}{ATT} & \multicolumn{1}{c}{ATNT} & ATE    \\
\midrule
   &       &       &  \\
(a) True treatment parameters & 0.471 & 0.315 & 0.365866 \\
   &       &       &  \\
(b) Kernel matching estimate & 0.546 & 0.394 & 0.443377 \\
\multicolumn{4}{l}{(Variability of estimation of pscores not taken into account)}  \\
   &       &       &  \\
(c) Nearest-neighbour matching estimates & 0.448 & 0.375 & 0.398856 \\
   &       &       &  \\
(d) Treatment estimates using OLS & 0.489096 & 0.489096 & 0.489096 \\
\multicolumn{4}{l}{Homogenous returns on trimmed data and specification of pscores as in    Q 1 (b)} \\
   &       &       &  \\
(e) Treatment estimates using Linear Regression & 0.587089 & 0.378109 & 0.44625 \\
   &       &       &  \\
(f) Treatment estimates using Re-weighting & 0.556587 & 0.417025 & 0.462531 \\
\bottomrule
\end{tabular}%
\label{tab:addlabel}%
\end{table}%

相关内容