[Tex/LaTex] \cmidrule with booktabs in beamer does not show up

beamerbooktabsrules

I am trying to use a coloured \cmidrule in a table in beamer – however, it does not show up. I have read Strange disappearing colored rules in beamer which indicates that this is a bug and discusses reasons and some possibilities to fix things by adding \kern. However, it does not actually show how to apply this to \cmidrule, just to other \hrule commands. My questions is: how do I apply this to \cmidrule? or is that not feasible?

MWE

\documentclass[pdftex,12pt,fleqn,xcolor=pdftex,table,usepdftitle=false]{beamer}
\pdfpageattr{/Group <</S /Transparency /I true /CS /DeviceRGB>>} 
\usepackage[T1]{fontenc}
\usepackage{bera}
\usepackage{arevmath}
\usepackage{booktabs}
\usecolortheme{shark}
\useoutertheme[glossy]{wuerzburg}
\begin{document}
\begin{frame}
\frametitle{booktabs with cmidrule}
\rowcolors*{2}{black!5}{structure!22}\arrayrulecolor{structure}
\begin{tabular}{lrrrrrr}
\toprule
& \multicolumn{6}{c}{Penalty} \\
\cmidrule{2-7}
$\hat{\lambda}_{i}$ 
& None & a & b & c & d& e \\
\midrule
1 &    10&  -11&   -4&   -8&    8 & 3\\
2 &    10&  -11&   -4&   -8&    8 & 3\\
\bottomrule
\end{tabular}
\end{frame}
\end{document}

enter image description here

Best Answer

Commenting on the linked question, Herbert states

I suppose a problem with \leaders [...] the definition of \hrulefill also uses the \kern\z@ [...]

The definition of \hrulefill is

\leavevmode\leaders\hrule\hfill\kern\z@

The booktabs commands that include \leaders in their definition are \@cmiderulea and \@cmidruleb:

\def\@cmidrulea{%
   \multispan\@cmidla&\multispan\@cmidlb
   \unskip\hskip\cmrkern@l%
  {\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill}%
   \hskip\cmrkern@r\cr}%
\def\@cmidruleb{%
    \multispan\@cmidlb
    \unskip\hskip \cmrkern@l%
   {\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill}%
    \hskip\cmrkern@r\cr}%

It seemed worth a try to add \kern\z@ after \hfill to both definitions. (For convenience, I used the etoolbox package to do so.) And indeed:

\documentclass[pdftex,12pt,fleqn,xcolor=pdftex,table,usepdftitle=false]{beamer}
\pdfpageattr{/Group <</S /Transparency /I true /CS /DeviceRGB>>} 
\usepackage[T1]{fontenc}
\usepackage{bera}
\usepackage{arevmath}
\usepackage{booktabs}
%\usecolortheme{shark}
%\useoutertheme[glossy]{wuerzburg}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@cmidrulea}{\hfill}{\hfill\kern\z@}{}{}
\patchcmd{\@cmidruleb}{\hfill}{\hfill\kern\z@}{}{}
\makeatother
\begin{document}
\begin{frame}
\frametitle{booktabs with cmidrule}
\rowcolors*{2}{black!5}{structure!22}\arrayrulecolor{structure}
\begin{tabular}{lrrrrrr}
\toprule
& \multicolumn{6}{c}{Penalty} \\
\cmidrule{2-7}
$\hat{\lambda}_{i}$ 
& None & a & b & c & d& e \\
\midrule
1 &    10&  -11&   -4&   -8&    8 & 3\\
2 &    10&  -11&   -4&   -8&    8 & 3\\
\bottomrule
\end{tabular}
\end{frame}
\end{document}

enter image description here