# Strange disappearing colored rules in beamer

I have received a booktabs bug report of \cmidrules that disappear when coloured rules are used inside beamer (together with colortbl). The problem can be illustrated with the following simple code and looks like an interaction between the beamer colour setup and \leaders. In the normal Latex classes the code is fine.

I know to little about the inner workings of beamer and hope there is someone here who can help or that can give a workaround. Note that the colour need to be grouped inside booktabs to prevent leaking.

EDIT: In an e-mail Michael Palmer suggested the addition of a \kern at the end of the grouping. This seems to work but the question is WHY?

Note: The standard tabular \cline also disappears inside beamer when the line color is set with the \arrayrulecolor of the colortbl package. So this is now also David Carlisle's problem :-)

Beamer class

\documentclass{beamer}

\begin{document}
\begin{frame}
INSIDE BEAMER CLASS\par\smallskip
\tfillA{2cm}{A}{B}: Works fine without colour\par
\tfillB{2cm}{A}{B}: Works fine with ungrouped colour\par
\tfillC{2cm}{A}{B}: Rule disappears with grouped colour\par
\tfillD{2cm}{A}{B}: Rule reappears with kern at end ?????
\end{frame}
\end{document}


Article class

\documentclass{article}
\usepackage{xcolor}

\begin{document}
INSIDE ARTICLE CLASS\par\smallskip
\tfillA{2cm}{A}{B}: Works fine without colour\par
\tfillB{2cm}{A}{B}: Works fine with colour  everywhere\par
\tfillC{2cm}{A}{B}: Works fine with grouped colour
\end{document}


-
this also works: \makebox[#1]{#2{\color{red}\hrulefill}#3} I suppose a problem with \leaders –  Herbert Feb 20 '13 at 15:05
@Herbert: The problem is that the \cmidrule in booktabs (and the standard \cline) uses \leaders internally. The colortbl package has the same problem inside beamer –  Danie Els Feb 20 '13 at 15:14
the definition of \hrulefill also uses the \kern\z@. I have no idea why it is important for beamer. –  Herbert Feb 20 '13 at 15:22
\null also works. –  bloodworks Feb 20 '13 at 15:29
a \kern after \leaders is usually to protect it from \unskip As for the note I might look but colortbl documentation says not to use \cline so any behaviour is user error. –  David Carlisle Feb 20 '13 at 21:10

Beamer, for whatever reason, redefines the latex color command \reset@color to do an unskip. That normally removes preceding white space, which you can save and restore with \lastskip but unfortunately \lastkip and \unskip "work" with \leaders but \lastskip only saves the glue component and so no record that there are leaders there is possible in classic tex (or etex).
All LaTeX \leader commands have a trailing \kern or box to prevent this, otherwise several standard commands including \newline which similarly do an \unskip would destroy \dotfill etc. (The LaTeX definition of \dotfill adds this, the original plain TeX one does not have it).
So while it is a bit surprising that Beamer does this, it is generally the case that a leaders followed by unknown commands ought to have the \kern there. \reset@color is inserted by \aftergroup at the closing } which is why the problem only affects the version that closes the group immediately after the leader. One could argue (not unreasonably) that \reset@color should not be an "unknown" command. Obviously it would be easy to patch it not to do that but without knowing the details of beamers workings and why it was changed, that may not be the best thing to do.
It looks then if a trailing \kern\z@ to protects against unskips is the best option to safeguard the code. It also works for colortbl if you add it to \@cline. –  Danie Els Feb 21 '13 at 1:17
See this answer of mine for an explanation of why beamer does this. In short, the overlay commands add \pdfliterals that would influence \lastskip without the \unskip business. So the \kern\z@ after the leader seems to be the way to go. (Ping, @Danie.) –  Hendrik Vogt Feb 21 '13 at 11:51
@cacamailg as discussed there isn't a patch required you just need to define your command so that the leaders is followed by \kern0pt or \mbox{} or anything else that will protect it from \unskip –  David Carlisle Apr 9 '13 at 13:33