A previous question asked how to underline equations in color (1). However, many of the solutions suggested don't work in LaTeX Beamer. I also had difficulties finding ways for simple customisation, such as adjusting the thickness of the underline. Promising efforts for coloured underlining in Beamer have been made (2), but I have not seen a solution that satifies all of the following main criteria:
- Underline both text and equations in colour in LaTex Beamer
- Adjustable thickness of the underline
- Compatibility with Beamer overlays, specifically in the way that overlaying underlines does not change vertical spacing within a slide
- Long underlined expressions do not force an early line break, rather the underline stretches over two lines of text.
Here's code for an example slide
\documentclass{beamer}
\useinnertheme{default}
\beamertemplatenavigationsymbolsempty
\begin{document}
\begin{frame}{Coloured Underlining}
Different parts of text can be underlined, using colours
such as green, red. The thickness of the underline can be set.
\vfill
Underlining is consistent with Beamer overlays.
\vfill
Underlining works as well in equations such
as $f(x) = \lambda\, e^x$ and
\begin{align*}
\mu = \frac{1}{2} \int_0^1 x f_{P_{ij}}(x)\,dx
+ \frac{1}{2} \int_0^1 f_{P_{ij}}(x)
\int_0^1 y \,f_{P_{ji}\vert P_{ij}}(y \mid x) \,dy \, dx.
\end{align*}
\vfill
Underlining longer expressions doesn't lead to lines
breaking early, but rather the underline stretches
across two lines of text.
\end{frame}
\end{document}
How can I implement an underline command to produce underlines in the slide as close as possible to the following graphic?
Best Answer
As you have found out there are several techniques how to implement underlines and none (of those I know) fulfills all of your requirements.
Therefore I have written a wrapper
\myul
which selects one technique to use in this case based on the context (math mode or normal mode). With an optional argument you can manually specify color, thickness, depth and the technique. You can change these settings for the entire current group with the command\setmyul
. For some options different values can be specified for math mode or text mode. For more details please see the comments in the code.Sometimes two runs are required.