Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
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

1 Answer 1

up vote 5 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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