[Tex/LaTex] Combining \rowcolor and \cmidrule

booktabscolorcolortbltables

I want to shade the heading of my table. It all worked fine until I started using \cmidrule. This is my output:

Example Table

Is there a way to shade the white space between the first and second row?

The code below redefines the toprule and midrule commands to account for the heading's shading.

\documentclass{article}

\usepackage{booktabs}
\usepackage{xcolor}
\usepackage{colortbl}

%%%%%% Set up the coloured tables %%%%%
\colorlet{tableheadcolor}{gray!25} % Table header colour = 25% gray
\colorlet{tablerowcolor}{gray!10} % Table row separator colour = 10% gray
\newcommand{\headcol}{\rowcolor{tableheadcolor}}
\newcommand{\rowcol}{\rowcolor{tablerowcolor}}

% The top-most line of a table
\newcommand{\topline}{\arrayrulecolor{black}\specialrule{0.1em}{\abovetopsep}{0pt}%
    \arrayrulecolor{tableheadcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
    \arrayrulecolor{black}}

% The line between the headings and the table body
\newcommand{\midline}{\arrayrulecolor{tableheadcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
    \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
    \arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
    \arrayrulecolor{black}}

%%%%%END: Set up the coloured tables %%%%%

\begin{document}
\begin{tabular}{ccc}
\topline
\headcol      & A & B\\ \cmidrule{2-3}
\headcol Blue & Red & Yellow\\ \midline
1 & 2 & 3 \\ \bottomrule 
\end{tabular}

\end{document}

Best Answer

The white space can be filled in using the \specialrule{<wd>}{<abovespace>}{<belowspace>} command. The modified table:

\begin{tabular}{ccc}
\topline
\headcol      & A & B\\
 \arrayrulecolor{tableheadcolor} \specialrule{6pt}{0pt}{-6pt} \arrayrulecolor{black}
 \cmidrule{2-3} 
 \headcol Blue & Red & Yellow\\
\midline
1 & 2 & 3 \\
\bottomrule
\end{tabular}