4

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}

marked as duplicate by Werner, karlkoeller, Jesse, OSjerick, lockstep Jan 23 '14 at 6:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

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}
  • Instead of 6pt use \newlength{\clinegapskip} \setlength{\clinegapskip}{3\cmidrulesep} \addtolength{\clinegapskip}{\cmidrulewidth} -- but I agree that the answer proposed as a duplicate is not the correct answer to this question (the linked answer applies only to colored columns not rows where the calculation is totally different) – Aubrey Blumsohn May 30 at 12:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.