以这种方式合并四列两对

以这种方式合并四列两对

在此处输入图片描述

可以有这样的表格吗?你能帮忙吗?

答案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

使用tabularraybooktabs包的两种解决方案(来自@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}

在此处输入图片描述

相关内容