通常,当我添加表格时,我会使用\usepackage{booktabs}
如下代码:
\begin{table}[ht]
\centering
\begin{tabular}{l|rrr}
\toprule
Country / Property & Population & Area & HDI \\\midrule
France & $66 \cdot 10^6$ & $\SI{668763}{\km\squared}$ & 0.89 \\
Germany & $81 \cdot 10^6$ & $\SI{357167}{\km\squared}$ & 0.92 \\
United States & $317 \cdot 10^6$ & $\SI{9629091}{\km\squared}$ & 0.94 \\\bottomrule
\end{tabular}
\caption{Information about countries}
\label{table:countries}
\end{table}
但是是否有任何语义的方式来标记表格标题行?
或者有一种方法可以改变整行/列的样式?
平均能量损失
\documentclass[a4paper]{scrartcl}
\usepackage{amssymb, amsmath} % needed for math
\usepackage[utf8]{inputenc} % this is needed for umlauts
\usepackage[ngerman]{babel} % this is needed for umlauts
\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
\usepackage[margin=2.5cm]{geometry} %layout
\usepackage{siunitx}
\usepackage{booktabs}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin document %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\newcolumntype{+}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}
\begin{table}[ht]
\centering
\begin{tabular}{+l|^r^r^r}
\toprule
\rowstyle{\bfseries}%
Country / Property & Population & Area & HDI \\\midrule
France & $66 \cdot 10^6$ & $\SI{668763}{\km\squared}$ & 0.89 \\
Germany & $81 \cdot 10^6$ & $\SI{357167}{\km\squared}$ & 0.92 \\
United States & $317 \cdot 10^6$ & $\SI{9629091}{\km\squared}$ & 0.94 \\\bottomrule
\end{tabular}
\caption{Information about countries}
\label{table:countries}
\end{table}
\end{document}
我目前所看到的
在www.latex-community.org我曾见过这样的情况:
\newcolumntype{+}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}
\begin{table}[ht]
\centering
\begin{tabular}{+l|^r^r^r}
\toprule
\rowstyle{\bfseries}%
Country / Property & Population & Area & HDI \\\midrule
France & $66 \cdot 10^6$ & $\SI{668763}{\km\squared}$ & 0.89 \\
Germany & $81 \cdot 10^6$ & $\SI{357167}{\km\squared}$ & 0.92 \\
United States & $317 \cdot 10^6$ & $\SI{9629091}{\km\squared}$ & 0.94 \\\bottomrule
\end{tabular}
\caption{Information about countries}
\label{table:countries}
\end{table}
答案1
与其试图改善左上角单元格中信息的显示效果,不如将信息理清,创建两组列——“国家”列和“财产”列,后者包含三个子列(人口、面积和人类发展指数 (HDI)),这样可能更有成效。
为了增强表格的可读性,从单元格中删除公因数(\cdot 10^6
和\km\squared
)并将该信息放在标题部分可能也是一个好主意。从编程美学的角度来看,选择S
第 2、3 和 4 列的列类型可能也是一个好主意,而不是为它们提供通用r
类型,然后用\SI
宏覆盖各个单元格。
我不会完全排除使用粗体字来显示标题单元格中的材料。但通常情况下,使用粗体字会让人觉得这是在绝望地(而且往往是徒劳地)尝试挽救设计不当的表格,使其不再无关紧要。
下面的截图显示了原始代码的输出以及实施上述建议的结果。如果我想进一步改进表格,我可能会从说明国家/地区的面积开始千平方公里——并将小数部分四舍五入。
\documentclass{article}
\usepackage{booktabs,siunitx,caption}
\begin{document}
\begin{table}[ht]
\caption{Information about countries}
\label{table:countries}
\centering
\begin{tabular}{l|rrr}
\toprule
Country / Property & Population & Area & HDI \\\midrule
France & $66 \cdot 10^6$ & $\SI{668763}{\km\squared}$ & 0.89 \\
Germany & $81 \cdot 10^6$ & $\SI{357167}{\km\squared}$ & 0.92 \\
United States & $317 \cdot 10^6$ & $\SI{9629091}{\km\squared}$ & 0.94 \\\bottomrule
\end{tabular}
\bigskip
\begin{tabular}{lS[table-format=3.0]
S[table-format=7.0]
S[table-format=1.2]}
\toprule
Country & \multicolumn{3}{c}{Property}\\
\cmidrule{2-4}
& {Population} & {Area} & {HDI} \\
& {(mio.)} & {(km\textsuperscript{2})}\\
\midrule
France & 66 & 668763 & 0.89 \\
Germany & 81 & 357167 & 0.92 \\
United States & 317 & 9629091 & 0.94 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
还可以创建表,如下所示。
\documentclass{article}
\usepackage{booktabs,siunitx,caption}
\begin{document}
\begin{table}[ht]
\caption{Information about countries}
\label{table:countries}
\centering
\begin{tabular*}{1.2\textwidth}{r|r|r||r|r|r||r|r|r}
\toprule
\multicolumn{9}{c}{Country}\\
\midrule
\multicolumn{3}{c}{France} & \multicolumn{3}{c}{Germany} & \multicolumn{3}{c}{United States}\\
\midrule
\multicolumn{3}{c}{Property}& \multicolumn{3}{c}{Property}& \multicolumn{3}{c}{Property}\\
\midrule
Population & Area &{HDI}& Population & Area &{HDI}&Population & Area &{HDI}\\
{(mio.)}& {(km\textsuperscript{2})}& &{(mio.)}& {(km\textsuperscript{2})}& &{(mio.)}& {(km\textsuperscript{2})}&\\
\midrule
66 & 668763 & 0.89 & 81 & 357167 & 0.92 & 317 & 9629091 & 0.94 \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}
输出: