I would like to create a gray cmidrule a la booktabs. I have created a gray midrule gmidrule
(extends entire table width) with different tighter space via
\newcommand{\gmidrule{\arrayrulecolor{lightgray}\specialrule{\lightrulewidth}{0.4\aboverulesep}{0.6\belowrulesep}\arrayrulecolor{black}}
Now, I would like to apply a light gray color, and identical separation as shown above, for a cmidrule
(partial rule), and call this variation gcmidrule
.
First issue is that the cmidrules are staggered. I would like to resolve this, but also adust the above and below rule sep.
\documentclass{article}
\usepackage{xparse}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\newcommand{\gmidrule}{\arrayrulecolor{lightgray}\specialrule{\lightrulewidth}{0.4\aboverulesep}{0.6\belowrulesep}\arrayrulecolor{black}}
\NewExpandableDocumentCommand{\gcmidrule}{ O{} D(){} m }{%
%% I would like to reduce the distance here as well, but the midrules are staggered
\arrayrulecolor{lightgray}%
\cmidrule{#3}%
% \cmidrule[#1](#2){#3}% supposed to be like this, but causes error. I'll worry about this later
\arrayrulecolor{black}%
}
\begin{document}
\begin{tabular}{lllll}\toprule
a & b & c & d & e \\\gmidrule
a & b & c & d & e \\\gcmidrule{1-2}\gcmidrule{4-5} % notice the stagger
a & b & c & d & e \\\bottomrule
\end{tabular}
\end{document}
Update:
This question is slightly helpful in that it helps align the cmidrules, however it does not adjust the above and below sep: How to omit vertical realignment when using cmidrule in different colors?
%% added this
% Correct for \cmidrule colour adjustment/vertical skip
\newcommand{\corcmidrule}[1][0pt]{% \corcmidrule[<len>]
\\[\dimexpr-\normalbaselineskip-\belowrulesep-\aboverulesep-#1\relax]%
}
%% add this in gcmidrule
\corcmidrule%
Still staggered, and adjusting the [0pt]
still leaves staggered.
Best Answer
\cmidrule
is written in a way to check if more\cmidrule
s follow it. If that is the case, it purposefully performs a vertical readjustment so the\cmidrule
s follow on the same line. So using (say)in your way would effectively translate to
While it's not incorrect to switch colours back-and-forth, the first
\cmidrule
just doesn't find that it is followed by another\cmidrule
. Hence, there's no vertical correction.The easiest way that makes the most sense is to copy the original definition(s) if
\cmidrule
(and subsidiary commands) and change them to show as\gcmidrule
(and subsidiaries), including the "checking ahead" part.