![在 threeparttable 环境中,表格宽度比文本宽度宽](https://linux22.com/image/316894/%E5%9C%A8%20threeparttable%20%E7%8E%AF%E5%A2%83%E4%B8%AD%EF%BC%8C%E8%A1%A8%E6%A0%BC%E5%AE%BD%E5%BA%A6%E6%AF%94%E6%96%87%E6%9C%AC%E5%AE%BD%E5%BA%A6%E5%AE%BD.png)
我有一张比 更宽的表格\textwidth
。表格中还有脚注,见下图:
我将表放在threeparttable
环境中,并尝试使用\makebox
中提到的命令这个问题使表格水平居中。但是,这不起作用。此外,K$
第二行的上标 a 和 ( ) 之间没有空格。我该如何解决这个问题?
以下是我的 MWE:
\documentclass[a4paper, 10pt]{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage[flushleft]{threeparttable}
\captionsetup{labelsep=period, skip=5pt}
\begin{document}
\begin{table}[h]
\centering
\begin{threeparttable}
\caption{Optimal results of Example 2}
\label{tab: results2}
\begin{tabular}{lccccccccc}
\toprule
Item & ref. 1 & ref. 2 & ref. 3 & ref. 4 & ref. 5 & ref. 6 & ref. 7 & ref. 8 & Our method\\
\midrule
Utility (kW) & 2000 & 3800 & 4200 & & & & & & \\
Capital cost\tnote{a} (k\$) & 163.27 & & & & & & & & \\
Total annual cost (k\$) & 2268.59 & & & & - & & & & \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\vspace*{-2pt}
\item[a] {\footnotesize Based on the cost parameters from ref. 6.}
\vspace*{-2pt}
\item[-] {\footnotesize Not reported in literature.}
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
答案1
当减小字体大小以使宽表格“适合”文本块的宽度时,LaTeX 不会按比例缩小列间空白量。为了挽救可读表格的机会,缩小列间空白量也很重要。
我建议您 (i) 重新组织表格的标题以收集重复的“Ref.”和 (ii) 使用环境tabular*
而不是基本tabular
环境。进行这两项更改后,仍然需要使用\scriptsize
,以便将主字体大小线性缩小 30%。
屏幕截图中的第一条水平线用于说明文本块的宽度。
\documentclass[a4paper, 10pt]{article}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup{labelsep=period, skip=5pt}
\usepackage[flushleft]{threeparttable}
\begin{document}
\hrule % just to illustrate width of textblock
\begin{table}[h]
\scriptsize
\setlength\tabcolsep{0pt} % let LaTeX determine whitespace between columns
\begin{threeparttable}
\caption{Optimal results of Example 2}
\label{tab:results2}
\begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}*{9}{c}}
\toprule
Item & \multicolumn{8}{c}{Ref.} & Our method\\
\cmidrule{2-9}
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\midrule
Utility (kW) & 2000 & 3800.00 & 4200.00 & 4200.00 & 4200.00 & 4200.00& 4200.00 & 4200.00 & 5000.00\\
Capital cost\tnote{a} (k\$) & 163.27 & & & & & & & & \\
Total annual cost (k\$) & 2268.59 & & & & -- & & & & \\
\bottomrule
\end{tabular*}
\begin{tablenotes}
\scriptsize
\item[a] Based on the cost parameters from ref.~6.
\item[--] Not reported in literature.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
如果您愿意在第一列中允许换行,则可以使用\footnotesize
(字体大小减少 20%)代替\scriptsize
。如果选择此方法,则可以使用tabularx
环境(而不是tabular*
上面使用的环境)来简化在第 1 列中获取最佳换行的过程。我还建议您考虑将第 2 列到第 10 列中的数字数据与各自的小数点对齐,以提高表格的可读性。我还会将看起来有点滑稽的 替换k\$
为10^\textsuperscript{3} \$
。
\documentclass[a4paper, 10pt]{article}
\usepackage{booktabs,tabularx,ragged2e,dcolumn}
\newcolumntype{Y}{>{\RaggedRight}X}
\newcolumntype{d}[1]{D..{#1}}
\usepackage{caption}
\captionsetup{labelsep=period, skip=5pt}
\usepackage[flushleft]{threeparttable}
\newcommand\mc[1]{\multicolumn{1}{@{}c@{}}{#1}} % handy shortcut macro
\begin{document}
\hrule % just to illustrate width of textblock
\begin{table}[h]
\footnotesize
\setlength\tabcolsep{1.5pt} % let LaTeX determine whitespace between columns
\begin{threeparttable}
\caption{Optimal results of Example 2}
\label{tab:results2}
\begin{tabularx}{\textwidth}{@{}Y*{9}{d{4.2}}@{}}
\toprule
Item & \multicolumn{8}{c}{Ref.} & \mc{Our method}\\
\cmidrule(lr){2-9}
& \mc{1} & \mc{2} & \mc{3} & \mc{4} & \mc{5} & \mc{6} & \mc{7} & \mc{8}\\
\midrule
Utility (kW) & 2000 & 3800.00 & 4200.00 & 4200.00 & 4200.00 & 4200.00& 4200.00 & 4200.00 & 5000.00\\
Capital cost\tnote{a} (10\textsuperscript{3}\,\$)
& 163.27 & & & & & & & & \\
Total annual cost (10\textsuperscript{3}\,\$)
& 2268.59 & & & & \mc{--} & & & & \\
\bottomrule
\end{tabularx}
\begin{tablenotes}
\item[a] Based on the cost parameters from ref.~6.
\item[--] Not reported in literature.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
答案2
它似乎\tnote
依赖于一个内部\TPToverlap
宏,使其吞掉前导空格。重新定义它以不使用它就可以了。
\renewcommand{\tnote}[1]{\textsuperscript{\TPTtagStyle{#1}}}
TPTtagStyle
(我保留了包定义中注释标记样式的原始行为。)
居中不起作用,因为表格不适合文本区域。您可以使用adjustbox
您链接的答案中提到的包:
\begin{adjustbox}{max width=\textwidth}
\begin{threeparttable}
...
\end{threeparttable}
\end{adjustbox}
梅威瑟:
\documentclass[a4paper, 10pt]{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage[flushleft]{threeparttable}
\captionsetup{labelsep=period, skip=5pt}
\pagestyle{empty}
% Add space after \tnote
\renewcommand{\tnote}[1]{\textsuperscript{\TPTtagStyle{#1}}}
% Use adjustbox to adjust the threeparttable env to textwidth
\usepackage{adjustbox}
\begin{document}
\listoftables
\begin{table}[h]
\begin{adjustbox}{max width=\textwidth}
\begin{threeparttable}
\caption{Optimal results of Example 2}
\label{tab: results2}
\begin{tabular}{lccccccccc}
\toprule
Item & ref. 1 & ref. 2 & ref. 3 & ref. 4 & ref. 5 & ref. 6 & ref. 7 & ref. 8 & Our method\\
\midrule
Utility (kW) & 2000 & 3800 & 4200 & & & & & & \\
Capital cost\tnote{a} (k\$) & 163.27 & & & & & & & & \\
Total annual cost (k\$) & 2268.59 & & & & - & & & & \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\vspace*{-2pt}
\item[a] {\footnotesize Based on the cost parameters from ref. 6.}
\vspace*{-2pt}
\item[-] {\footnotesize Not reported in literature.}
\end{tablenotes}
\end{threeparttable}
\end{adjustbox}
\end{table}
\end{document}