15

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

  • There always have been some problems with booktabs and colortbl although in v1.6180 of booktabs they have been tackled. So in this case it seems to be some additional interference with beamer since trying this with report i get correct results. (BTW rules and colored rows is a pretty ugly thing) – bloodworks Apr 6 '13 at 9:52
6

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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