I'm trying to use the soul package to get highlighting via \hl{some text}
. I'd like to do this in overlays in beamer. I'm trying to follow the guidelines in section 9.6.1 of the beamer manual to make the \hl
command overlay aware. What i'm using is
\renewcommand<>{\hl}[1]{\only#2{\beameroriginal{\hl}}{#1}}
That setup sorta/kinda works, but not exactly.
- The
\hl
command is overlay-aware in xelatex, but not in pdflatex or lualatex. I generally use lualatex, so that would be my preference. (Peter Grill has addressed this part in the first half of his answer) - The overlays tend to reflow the text a bit, in a way that makes the highlighted text jump around from slide to slide in an awkward manner. You'll see that if you run the example below through xelatex. (Actually, you'll see it in all the engines, but only with the highlights in xelatex). (Peter addressed this in the TikZ part of his answer)
I've attached an MWE of the problem, which I'm sure is some simple ignorance on my part, but I can't seem to resolve.
\documentclass[presentation]{beamer}
\usepackage{xcolor,soul}
\definecolor{lightblue}{rgb}{.90,.95,1}
\sethlcolor{lightblue}
\renewcommand<>{\hl}[1]{\only#2{\beameroriginal{\hl}}{#1}}
\begin{document}
\begin{frame} {Some possibly highlighted text}
This is some normal text
\hl<2>{I'd like this text to appear on both slides, but only be
highlighted from the second slide}
\hl<3>{I'd like this text to appear on both slides, but only be
highlighted from the second slide. This is a long one, so it should
be more than one line}
This is some normal text
\end{frame}
\end{document}
Best Answer
Using
soul
package:Looks like the problem is that
beamer
redefines things. Using the patch from Why is it that coloring in soul in beamer is not visible seems to work:Using
tikz
package:As Andrew Stacey mentioned int he comments, there is a
tikzmark
solution as well. Using the code from How to "highlight" text/formulas with tikz?, we get:Notes:
Using this solution, the text is identical across the frames.
This required a slight tweak from the code at How to "highlight" text/formulas with tikz?. The
highlighter width
was increased form12pt
:Without this there was additional spacing in between the highlighted lines of the second paragraph.
This does require two runs. First one to determine the locations, and the second to do the drawing.
The
\tikzmark
is from Adding a large brace next to a body of text.Further Enhancements:
Code (
soul
):Code (
tikz
):