\multicolumn 的表头问题

\multicolumn 的表头问题

我一直在尝试为我的硕士论文制作一些美观的表格。这个链接对我帮助很大:具有交替行颜色的专业表格?

然而,挑战仍然存在。我真的不知道如何使用上述链接提供的信息来生成具有多行标题的表格。我将尝试通过一个例子让事情变得更容易理解:

这是我的代码:

\begin{table}[htp]
\begin{center}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l r r}
\topline
\headcol statement & \multicolumn{2}{c}{mean rates}  \\
\headcol  & system A & system B \\
\midline
      1. statement 1 & \textbf{4.2} & 4.1\\
\rowcol 2. statement 2 & \textbf{3.8} & 3.7 \\
      3. statement 3 & \textbf{4.2} & 4.0 \\
\rowcol 4. statement 4 & \textbf{4.3 }& 4.2\\
\bottomlinec
\end{tabular}
\end{center}
\caption[First table]{First table}
\label{tab:statements_group_1}
\end{table}

我使用了以下定义(来自上一个链接)

\documentclass{article}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{colortbl}% http://ctan.org/pkg/colortbl
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\colorlet{tableheadcolor}{gray!25} % Table header colour = 25% gray
\newcommand{\headcol}{\rowcolor{tableheadcolor}} %
\colorlet{tablerowcolor}{gray!10} % Table row separator colour = 10% gray
\newcommand{\rowcol}{\rowcolor{tablerowcolor}} %
% Command \topline consists of a (slightly modified) \toprule followed a \heavyrule rule of colour tableheadcolor (hence, 2 separate rules)
\newcommand{\topline}{\arrayrulecolor{black}\specialrule{0.1em}{\abovetopsep}{0pt}%
\arrayrulecolor{tableheadcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{black}}
% Command \midline consists of 3 rules (top colour tableheadcolor, middle colour black, bottom colour white)
\newcommand{\midline}{\arrayrulecolor{tableheadcolor}  \specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
\arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{black}}
% Command \rowmidlinecw consists of 3 rules (top colour tablerowcolor, middle colour black, bottom colour white)
\newcommand{\rowmidlinecw}{\arrayrulecolor{tablerowcolor}  \specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
\arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{black}}
% Command \rowmidlinewc consists of 3 rules (top colour white, middle colour black, bottom colour tablerowcolor)
\newcommand{\rowmidlinewc}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
\arrayrulecolor{tablerowcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{black}}
% Command \rowmidlinew consists of 1 white rule \newcommand{\rowmidlinew}   {\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}}
% Command \rowmidlinec consists of 1 tablerowcolor rule
\newcommand{\rowmidlinec}{\arrayrulecolor{tablerowcolor}  \specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}}
% Command \bottomline consists of 2 rules (top colour
 \newcommand{\bottomline}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
 \arrayrulecolor{black}\specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%
 \newcommand{\bottomlinec}{\arrayrulecolor{tablerowcolor}  \specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}\specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%

我想知道您是否能帮我找出为什么标题的一部分(平均费率)没有用深灰色显示。

答案1

这篇文章太长了,不适合作为评论,所以我用了一个答案。

你不小心注释掉了你链接的问题答案中给出的部分代码,并留下了一些括号不匹配的虚假代码。问题出在以

% Command \rowmidlinew consists of 1 white rule \newcommand{\rowmidlinew}...

仅限第一部分

% Command \rowmidlinew consists of 1 white rule

需要评论;不是\newcommand...部分。

一旦纠正了这个问题,就像下面的代码一样,示例代码将会运行而不会出现错误,并产生所需的输出:

\documentclass{article}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{colortbl}% http://ctan.org/pkg/colortbl
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\colorlet{tableheadcolor}{gray!25} % Table header colour = 25% gray
\newcommand{\headcol}{\rowcolor{tableheadcolor}} %
\colorlet{tablerowcolor}{gray!10} % Table row separator colour = 10% gray
\newcommand{\rowcol}{\rowcolor{tablerowcolor}} %
% Command \topline consists of a (slightly modified) \toprule followed a \heavyrule rule of colour tableheadcolor (hence, 2 separate rules)
\newcommand{\topline}{\arrayrulecolor{black}\specialrule{0.1em}{\abovetopsep}{0pt}%
\arrayrulecolor{tableheadcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{black}}
% Command \midline consists of 3 rules (top colour tableheadcolor, middle colour black, bottom colour white)
\newcommand{\midline}{\arrayrulecolor{tableheadcolor}  \specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
\arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{black}}
% Command \rowmidlinecw consists of 3 rules (top colour tablerowcolor, middle colour black, bottom colour white)
\newcommand{\rowmidlinecw}{\arrayrulecolor{tablerowcolor}  \specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
\arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{black}}
% Command \rowmidlinewc consists of 3 rules (top colour white, middle colour black, bottom colour tablerowcolor)
\newcommand{\rowmidlinewc}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
\arrayrulecolor{tablerowcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{black}}
% Command \rowmidlinew consists of 1 white rule 
\newcommand{\rowmidlinew}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}}
% Command \rowmidlinec consists of 1 tablerowcolor rule
\newcommand{\rowmidlinec}{\arrayrulecolor{tablerowcolor}  \specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}}
% Command \bottomline consists of 2 rules (top colour
 \newcommand{\bottomline}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
 \arrayrulecolor{black}\specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%
 \newcommand{\bottomlinec}{\arrayrulecolor{tablerowcolor}  \specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}\specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%

\begin{document}

\begin{table}[htp]
\begin{center}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l r r}
\topline
\headcol statement & \multicolumn{2}{c}{mean rates}  \\
\headcol  & system A & system B \\
\midline
      1. statement 1 & \textbf{4.2} & 4.1\\
\rowcol 2. statement 2 & \textbf{3.8} & 3.7 \\
      3. statement 3 & \textbf{4.2} & 4.0 \\
\rowcol 4. statement 4 & \textbf{4.3 }& 4.2\\
\bottomlinec
\end{tabular}
\end{center}
\caption[First table]{First table}
\label{tab:statements_group_1}
\end{table}
\end{document}

在此处输入图片描述

相关内容