![以这种方式合并四列两对](https://linux22.com/image/470601/%E4%BB%A5%E8%BF%99%E7%A7%8D%E6%96%B9%E5%BC%8F%E5%90%88%E5%B9%B6%E5%9B%9B%E5%88%97%E4%B8%A4%E5%AF%B9.png)
答案1
您可以使用\multicolumn
合并单元格并\cline
创建横跨特定列的水平线。以下示例应生成所需的表格:
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{table}[!h]
\centering
\begin{tabular}{|c|c|c|c|c|}
\hline
{} & \multicolumn{2}{c|}{solubility} & \multicolumn{2}{c|}{thermal stability}\\ \cline{2-5}
{} & calcium hydroxide & barium hydroxide & calcium carbonate & barium carbonate\\ \hline
\textbf{A} & higher & lower & higher & lower\\
\textbf{B} & higher & lower & lower & higher\\
\textbf{C} & lower & higher & higher & lower\\
\textbf{D} & lower & higher & lower & higher\\ \hline
\end{tabular}
\end{table}
\end{document}
答案2
这里有四种排版表格的方法。比较它们并做出选择。
\documentclass{article}
\usepackage{booktabs}
\usepackage{chemformula}
\begin{document}
\section{Best} % George
\begin{tabular}{@{}ccccc@{}}
\toprule
& \multicolumn{2}{c}{solubility} & \multicolumn{2}{c}{thermal stability}\\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
& \ch{Ca(OH)2} & \ch{Ba(OH)2} & \ch{CaCO3} & \ch{BaCO3} \\
\midrule
\textbf{A} & higher & lower & higher & lower\\
\textbf{B} & higher & lower & lower & higher\\
\textbf{C} & lower & higher & higher & lower\\
\textbf{D} & lower & higher & lower & higher\\
\bottomrule
\end{tabular}
\section{Good} % Clint Eastwood
\begin{tabular}{@{}ccccc@{}}
\toprule
& \multicolumn{2}{c}{solubility} & \multicolumn{2}{c}{thermal stability}\\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
& calcium & barium & calcium & barium \\
& hydroxide & hydroxide & carbonate & carbonate \\
\midrule
\textbf{A} & higher & lower & higher & lower\\
\textbf{B} & higher & lower & lower & higher\\
\textbf{C} & lower & higher & higher & lower\\
\textbf{D} & lower & higher & lower & higher\\
\bottomrule
\end{tabular}
\section{Bad} % Lee Van Cleef
\begin{tabular}{|c|c|c|c|c|}
\hline
& \multicolumn{2}{c|}{solubility} & \multicolumn{2}{c|}{thermal stability}\\
\cline{2-5}
& calcium & barium & calcium & barium \\
& hydroxide & hydroxide & carbonate & carbonate \\
\hline
\textbf{A} & higher & lower & higher & lower\\
\textbf{B} & higher & lower & lower & higher\\
\textbf{C} & lower & higher & higher & lower\\
\textbf{D} & lower & higher & lower & higher\\
\bottomrule
\end{tabular}
\section{Ugly} % Eli Wallach
\begin{tabular}{|c|c|c|c|c|}
\hline
& \multicolumn{2}{c|}{solubility} & \multicolumn{2}{c|}{thermal stability}\\
\cline{2-5}
& calcium hydroxide & barium hydroxide & calcium carbonate & barium carbonate \\
\hline
\textbf{A} & higher & lower & higher & lower\\
\textbf{B} & higher & lower & lower & higher\\
\textbf{C} & lower & higher & higher & lower\\
\textbf{D} & lower & higher & lower & higher\\
\bottomrule
\end{tabular}
\end{document}
答案3
使用tabularray
和booktabs
包的两种解决方案(来自@egreg 答案的“好”和“丑”):
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\begin{table}[htb]
\centering
\begin{tblr}{vlines,
colspec = { Q[c, font=\bfseries] *{4}{Q[c]} },
cell{1}{1} = {r=2}{},
cell{1}{even} = {c=2}{},
}
\toprule
& solubility
& & thermal stability
& \\
\midrule
& calcium hydroxide
& barium hydroxide
& calcium carbonate
& barium carbonate \\
\midrule
A & higher & lower & higher & lower \\
B & higher & lower & lower & higher \\
C & lower & higher & higher & lower \\
D & lower & higher & lower & higher \\
\bottomrule
\end{tblr}
\end{table}
\begin{table}[htb]
\centering
\begin{tblr}{colspec = { Q[c, font=\bfseries] *{4}{Q[c]} },
cell{1}{even} = {c=2}{},
}
\toprule
& solubility
& & thermal stability
& \\
\cmidrule[lr]{2-3} \cmidrule[lr]{4-5}
& {calcium\\ hydroxide}
& {barium\\ hydroxide}
& {calcium\\ carbonate}
& {barium\\ carbonate} \\
\midrule
A & higher & lower & higher & lower \\
B & higher & lower & lower & higher \\
C & lower & higher & higher & lower \\
D & lower & higher & lower & higher \\
\bottomrule
\end{tblr}
\end{table}
\end{document}