![使用和不使用 threeparttable 的表格格式](https://linux22.com/image/317413/%E4%BD%BF%E7%94%A8%E5%92%8C%E4%B8%8D%E4%BD%BF%E7%94%A8%20threeparttable%20%E7%9A%84%E8%A1%A8%E6%A0%BC%E6%A0%BC%E5%BC%8F.png)
我一直在尝试用 LaTeX 生成附加表格。我用两种方法完成了这项工作,并且对这两种方法都进行了查询。第一种方法我没有使用该threeparttable
包,第二种方法我使用了它。这是因为当我在表格下搜索添加注释的帮助时,我才知道,threeparttable
而这几乎是我即将完成第一种方法的时候。
首先,我有一个普遍的问题,即我该如何格式化第一列中未左对齐的文本?我的意思是包含以下项目的文本(石油、烟煤、褐煤等)。我想与我在这两个代码中所做的方法相比,一定有更好的方法可以做到这一点。我过去常常\
添加空格,直到文本处于我想要的位置。
在第一个代码中,我无法像原始表格中所示那样在新行中写入第二个表格注释。有什么建议吗?
在第二个代码中,我无法\hline
在第二个表格注释之后和最后一行“来源:能量平衡.....”上方绘制。有什么建议吗?
以下是代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array, multirow}
\usepackage{caption,tabularx,booktabs}
\begin{document}
\begin{table}{\bfseries Primary Energy Consumption}\\[0.1ex]
\setlength{\extrarowheight}{1pt}
\begin{tabular*}{118 mm}{p{40mm}@{\hspace{30mm}} llrr @{}}
\hline
Energy Source &1975 &1980 &1986\\[-0.1ex]
\hline
Total Consumption\\
(in million tons of BCU$^{a}$) of which (percentages) \parbox[t]{15mm} &347.7 &390.2 &285.0\\
\ \ \ \ \ \ \ \ \ \ \ \ \ petroleum &52.1 &47.6 &43.2\\
\ \ \ \ \ \ \ \ \ \ \ \ \ bituminous coal &19.1 &19.8 &20.0 \\
\ \ \ \ \ \ \ \ \ \ \ \ \ brown coal &9.9 &10.0 &8.6 \\
\ \ \ \ \ \ \ \ \ \ \ \ \ natural gas &14.2 &16.5 &15.1 \\
\ \ \ \ \ \ \ \ \ \ \ \ \ nuclear energy &2.0 &3.7 &10.1 \\
\ \ \ \ \ \ \ \ \ \ \ \ \ other$^{b}$ &2.7 &2.4 &3.0 \\ \cline{1-1}
\multicolumn{4}{p{.9\textwidth}}{$^{a}$BCU = Bituminous Coal Unit (1 ton BCU corresponds to the heating equivalent of 1 ton of bituminous coal = 8140 kwh) $^{b}$Wind, water, solar energy, etc.}
\\
\hline
\end{tabular*}\\[0.1ex]
\emph{Source:} Energy Balance Study Group, Essen 1987.
\end{table}
\end{document}
这是第二段代码;
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array, multirow}
\usepackage{caption,booktabs}
\usepackage[flushleft]{threeparttable}
\begin{document}
\begin{table}
\begin{threeparttable}
\caption{Primary Energy Consumption}
\begin{tabular*}{118 mm}{p{40mm}@{\hspace{30mm}} llrr @{}}
\toprule
Energy Source &1975 &1980 &1986\\[-0.1ex]
\midrule
Total Consumption\\
(in million tons of BCU$^{a}$) of which (percentages) \parbox[t]{15mm} &347.7 &390.2 &285.0\\
\ \ \ \ \ \ \ \ \ \ \ \ \ petroleum &52.1 &47.6 &43.2\\
\ \ \ \ \ \ \ \ \ \ \ \ \ bituminous coal &19.1 &19.8 &20.0 \\
\ \ \ \ \ \ \ \ \ \ \ \ \ brown coal &9.9 &10.0 &8.6 \\
\ \ \ \ \ \ \ \ \ \ \ \ \ natural gas &14.2 &16.5 &15.1 \\
\ \ \ \ \ \ \ \ \ \ \ \ \ nuclear energy &2.0 &3.7 &10.1 \\
\ \ \ \ \ \ \ \ \ \ \ \ \ other$^{b}$ &2.7 &2.4 &3.0 \\
\bottomrule
\end{tabular*} %\\[0.1ex]
\begin{tablenotes}
\small
\item $^{a}$BCU = Bituminous Coal Unit (1 ton BCU corresponds to the heating equivalent of 1 ton of bituminous coal = 8140 kwh
\item $^{b}$Wind, water, solar energy, etc.
\end{tablenotes}
\emph{Source:} Energy Balance Study Group, Essen 1987.
\end{threeparttable}
\end{table}
\end{document}
答案1
我会这样做:
% arara: pdflatex
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{caption,booktabs}
\usepackage[flushleft]{threeparttable}
\usepackage{siunitx}
\begin{document}
\begin{table}
\centering
\begin{threeparttable}
\caption[Primary Energy Consumption]{Primary Energy Consumption (\emph{Source:} Energy Balance Study Group, Essen 1987.)}
\begin{tabular}{p{1.5cm}l*{3}{S[table-format=3.1]}} % adapt the tabbing width with the p column!
\toprule
\multicolumn{2}{l}{Energy Source} & {1975} & {1980} & {1986} \\
\midrule
\multicolumn{2}{l}{Total Consumption} & & & \\
\multicolumn{2}{l}{(in million tons of BCU\tnote{a}~)} & 347.7 & 390.2 & 285.0 \\
\multicolumn{2}{l}{of which (percentages)} & & & \\
& petroleum & 52.1 & 47.6 & 43.2 \\
& bituminous coal & 19.1 & 19.8 & 20.0 \\
& brown coal & 9.9 & 10.0 & 8.6 \\
& natural gas & 14.2 & 16.5 & 15.1 \\
& nuclear energy & 2.0 & 3.7 & 10.1 \\
& other\tnote{b} & 2.7 & 2.4 & 3.0 \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\small
\item[a] BCU = Bituminous Coal Unit (\SI{1}{\tonne} BCU corresponds to the heating equivalent of \SI{1}{\tonne} of bituminous coal $= \SI{8140}{\kilo\watt\hour}$
\item[b] Wind, water, solar energy, etc.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
我希望代码是不言自明的。
编辑:或者,如果您希望将“(百分比)”与下面的行对齐(感谢 Enrico):
\begin{table}
\centering
\begin{threeparttable}
\caption[Primary Energy Consumption]{Primary Energy Consumption (\emph{Source:} Energy Balance Study Group, Essen 1987.)}
\begin{tabular}{l@{\hspace{.4cm}}l*{3}{S[table-format=3.1]}} % adapt the tabbing width with the \hspace
\toprule
\multicolumn{2}{l}{Energy Source} & {1975} & {1980} & {1986} \\
\midrule
\multicolumn{2}{l}{Total Consumption} & & & \\
\multicolumn{2}{l}{(in million tons of BCU\tnote{a}~)} & 347.7 & 390.2 & 285.0 \\
of which & (percentages) & & & \\
& petroleum & 52.1 & 47.6 & 43.2 \\
& bituminous coal & 19.1 & 19.8 & 20.0 \\
& brown coal & 9.9 & 10.0 & 8.6 \\
& natural gas & 14.2 & 16.5 & 15.1 \\
& nuclear energy & 2.0 & 3.7 & 10.1 \\
& other\tnote{b} & 2.7 & 2.4 & 3.0 \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\small
\item[a] BCU = Bituminous Coal Unit (\SI{1}{\tonne} BCU corresponds to the heating equivalent of \SI{1}{\tonne} of bituminous coal $= \SI{8140}{\kilo\watt\hour}$
\item[b] Wind, water, solar energy, etc.
\end{tablenotes}
\end{threeparttable}
\end{table}