带有 threeparttable 的表格宽度是否小于注释和标题?

带有 threeparttable 的表格宽度是否小于注释和标题?

我正在尝试创建一个相当薄的表格,其标题和注释比表格本身的主体更宽。我的目的不是让表格变宽,因为这会使表格看起来很丑,而且值似乎丢失了。有没有办法简单顺利地解决这个问题?非常感谢每一条评论!

\documentclass[12pt]{article}
\usepackage{threeparttable}
\usepackage{booktabs}

\begin{document}


\begin{table}[h]
\centerline{
\begin{threeparttable}
\caption{The is ment to be a very long table caption, which is wider than the table itself.}
\label{table:meanerrorbaseline}

\begin{tabular}{cc}
\toprule
Endowment & Mean error \\ 
\midrule
0         & 1.67       \\
1         & 1.49*      \\
2         & 1.42**     \\
3         & 1.30***    \\
4         & 1.15***    \\
5         & 1.15***    \\
6         & 1.09***    \\
7         & 1.02***    \\
8         & 0.92***    \\
9         & 0.85***    \\
10        & 0.76**     \\
\bottomrule
\end{tabular}

\begin{tablenotes}
  \small
     \item The note is ment to be wider than the table itself, without having to make  the table wider and making it look ugly. 
   \end{tablenotes}
\end{threeparttable}
}
\end{table}
\end{document}

答案1

我仍然对该命令有疑问\centerline;这不是最好的居中命令,我建议使用环境\begin{center}{\centering ... }代替。

因此,你的问题的真正答案是使用

\renewcommand{\TPTminimum}{\linewidth}

重新定义 threeparttable 环境中的标题和注释所使用的最小空间量。这样做会得到一个严格意义上来说符合您要求的结果:

\documentclass[12pt]{article}
\usepackage{threeparttable}
\usepackage{booktabs}

\begin{document}


\begin{table}[h]

\begin{threeparttable}
\renewcommand{\TPTminimum}{\linewidth}
\caption{The is ment to be a very long table caption, which is wider than the table itself.}
\label{table:meanerrorbaseline}
{\centering
\begin{tabular}{cc}
\toprule
Endowment & Mean error \\ 
\midrule
0         & 1.67       \\
1         & 1.49*      \\
2         & 1.42**     \\
3         & 1.30***    \\
4         & 1.15***    \\
5         & 1.15***    \\
6         & 1.09***    \\
7         & 1.02***    \\
8         & 0.92***    \\
9         & 0.85***    \\
10        & 0.76**     \\
\bottomrule
\end{tabular}
}
\begin{tablenotes}
  \small
     \item The note is ment to be wider than the table itself, without having to make  the table wider and making it look ugly. 
   \end{tablenotes}
\end{threeparttable}

\end{table}
\end{document}

...看起来像这样:

桌子宽偏离中心

你的下一个合乎逻辑的问题是,“如何将表格置于标题的中心?”我能找到的唯一推荐的解决方案是为什么我的表格没有用 threeparttable 居中?。那里的答案要么省略了表格顶部的标题,要么没有处理宽表问题(省略\renewcommand{\TPTminimum}{...})。使用该\makebox...解决方案,我们接近所需的结果,但前提是标题被省略或移至底部:

\documentclass[]{article}

\usepackage{threeparttable}
\usepackage{booktabs}

\begin{document}

\begin{table}[h]
\begin{threeparttable}
\renewcommand{\TPTminimum}{\linewidth}
%\caption{The is ment to be a very long table caption, which is wider than the table itself.}
%\label{table:meanerrorbaseline}
\makebox[\linewidth]{%
\begin{tabular}{cc}
\toprule
Endowment & Mean error \\ 
\midrule
0         & 1.67 \\
1         & 1.49*      \\
2         & 1.42**     \\
3         & 1.30***    \\
4         & 1.15***    \\
5         & 1.15***    \\
6         & 1.09***    \\
7         & 1.02***    \\
8         & 0.92***    \\
9         & 0.85***    \\
10        & 0.76**     \\
\bottomrule
\end{tabular}}
\begin{tablenotes}
  \small
  \item The note is meant to be wider than the table itself, without having to make  the table wider and making it look ugly. 
   \end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

如果没有标题,则显示为:

宽表,无标题,居中

那么我们如何才能同时实现这两个目标呢?我想到的解决方案是在表格两侧添加额外的列来填充表格,使其在标题内居中。这有点像黑客行为,但它以一种其他更优雅的解决方案无法做到的方式解决了这个问题。

代码:

\documentclass[]{article}

\usepackage{threeparttable}
\usepackage{booktabs}

\begin{document}

\begin{table}[h]
\begin{threeparttable}
%\renewcommand{\TPTminimum}{\linewidth}
\caption{The is ment to be a very long table caption, which is wider than the table itself.}
\label{table:meanerrorbaseline}
\begin{tabular}{cccc}
\cmidrule[\heavyrulewidth]{2-3} % \toprule
~\rule{1in}{0in} & Endowment & Mean error  & \rule{1in}{0in}~ \\ 
\cmidrule[\lightrulewidth]{2-3} % \midrule
& 0         & 1.67 &  \\
& 1         & 1.49*    &   \\
& 2         & 1.42**    &  \\
& 3         & 1.30***  &   \\
& 4         & 1.15***   &  \\
& 5         & 1.15***   &  \\
& 6         & 1.09***   &  \\
& 7         & 1.02***   &  \\
& 8         & 0.92***   &  \\
& 9         & 0.85***   &  \\
& 10        & 0.76**    &  \\
\cmidrule[\heavyrulewidth]{2-3} % \bottomrule
\end{tabular}
\begin{tablenotes}
  \small
  \item The note is meant to be wider than the table itself, without having to make  the table wider and making it look ugly. 
   \end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

显示为:

宽标题,居中表格

答案2

我想跟进 cslstr 的解决方案 2/3。

如果将标题放在三部分表格之外但在表格环境之内,则居中和标题就可以协同工作,而不需要解决方案 3/3 中的“ hack”。

代码:

\documentclass[]{article}

\usepackage{threeparttable}
\usepackage{booktabs}

\begin{document}

\begin{table}[h]
\caption{The is ment to be a very long table caption, which is wider than the table itself.}
\label{table:meanerrorbaseline}
\begin{threeparttable}
\renewcommand{\TPTminimum}{\linewidth}
\makebox[\linewidth]{%
\begin{tabular}{cc}
\toprule
Endowment & Mean error \\ 
\midrule
0         & 1.67 \\
1         & 1.49*      \\
2         & 1.42**     \\
3         & 1.30***    \\
4         & 1.15***    \\
5         & 1.15***    \\
6         & 1.09***    \\
7         & 1.02***    \\
8         & 0.92***    \\
9         & 0.85***    \\
10        & 0.76**     \\
\bottomrule
\end{tabular}}
\begin{tablenotes}
  \small
  \item The note is meant to be wider than the table itself, without having to make  the table wider and making it look ugly. 
   \end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

结果:

结果

答案3

在这种情况下,使用threeparttable不再有用,因为这个解决方案存在缺陷:

  • 默认情况下,它无法正确管理更宽的 Notes(重新定义\TPTminimum不是为了做到这一点)
  • 当你对它进行破解时,它会破坏定心。
  • 它不直接构建枚举注释(需要为每个注释手动添加引用字符)

我自己的简单的解决方案基于\parbox并且不使用的threeparttable是:

\documentclass[]{article}
\usepackage{booktabs}
\begin{document}

\begin{table}[h]
\centering
\caption{The is meant to be a very long table caption, which is wider than the table itself.}
\label{table:meanerrorbaseline}
\begin{tabular}{cc}
\toprule
Endowment & Mean error \\ 
\midrule
0         & 1.67       \\
1         & 1.49*      \\
2         & 1.42**     \\
3         & 1.30***    \\
4         & 1.15***    \\
5         & 1.15***    \\
6         & 1.09***    \\
7         & 1.02***    \\
8         & 0.92***    \\
9         & 0.85***    \\
10        & 0.76**     \\
\bottomrule
\end{tabular}
\parbox{\textwidth}{\small%
\vspace{1eX} % If wanted space after the bottomrule
The note is meant to be wider than the table itself, without having to make the table wider and making it look ugly.}
\end{table}

\end{document}

结果:

代码结果

评论:

  • 表格未发生改变。
  • 宽度\parbox可以调整为任何想要的值(使用\textwidth\linewidth可获得更好的效果)
  • 之后的垂直间距\bottomrule设置为一个“X”大小\vspace(因此它与字体大小相关)。表格后和注释前的间距的另一种解决方案可能是使用\setlength{\belowbottomsep}{1eX}来更改\bottomrule间距(警告:在所有图形上有效!)
  • Itemize 环境在 parbox 内运行良好,因此多个注释不是问题(但由于 itemize 以额外的间距开始,因此间距可能会被删除)。
  • 只需手动添加参考字符(*在示例中,但如果需要,也可以使用大写字母/数字)

答案4

这个答案,Ulrike Fisher 说threeparttable挂钩tabular来获取标题和注释的宽度。

tabular她利用es周围的环境解决了这个问题\parbox

她的解决方案也可以在这里应用。对于你的情况,使用tabularx你喜欢的宽度的边框会更简单。

对于标题,请将其放在threeparttable放在M. Duck 的回答

\documentclass[12pt]{article}
\usepackage{threeparttable}
\usepackage{booktabs}
\usepackage{tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}
\begin{table}[h]\centering
\caption{\label{table:meanerrorbaseline}
The is ment to be a very long table caption, which is wider than the table itself.}
\begin{threeparttable}
\begin{tabularx}{\linewidth}{@{}Y@{}}
\begin{tabular}{cc}
\toprule
Endowment & Mean error\tnote{a}\\ 
\midrule
0         & 1.67       \\
1         & 1.49*      \\
2         & 1.42**     \\
3         & 1.30***    \\
4         & 1.15***    \\
5         & 1.15***    \\
6         & 1.09***    \\
7         & 1.02***    \\
8         & 0.92***    \\
9         & 0.85***    \\
10        & 0.76**     \\
\bottomrule
\end{tabular}
\end{tabularx}
\begin{tablenotes}[flushleft]
  \small\item[a] The note is ment to be wider than the table itself, without having to make  the table wider and making it look ugly. 
   \end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}

在此处输入图片描述

相关内容