4

I'm using beamer, and would like to color certain bullets on certain slides. Unfortunately, using the \color command seems to mess up the vertical spacing in lists. For example, here are two side-by-side slides. I would like the slides to have the exact same content and spacing other than the color of the second bullet. However, latex seems to be inserting extra space around the \color command.

enter image description here

The code to produce these slides is here:

\documentclass[10pt]{beamer}

\setbeamersize{text margin left=0pt, text margin right=0pt}
\paperheight=24mm \paperwidth=40mm

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{background}[grid]

\begin{document}

\begin{frame}[plain]
\bfseries
\begin{itemize}
  \item Here's a bullet
  \begin{itemize}
    \item And a sub-bullet
  \end{itemize}
\only<2>{\color{structure.fg}}
  \item This will be blue
  \begin{itemize}
    \item On overlay 2
  \end{itemize}
\end{itemize}
{\color{red}\hrule height .5pt}
\end{frame}

\end{document}

The beamer alertenv environment should handle this, but it works around the problem by calling \color{.} even in the event that you are not activating it. This is not a good solution, because it messes up the vertical spacing in all cases. (It makes lists look very bad, where there is extra space before bullets just because they happen to turn red on some later overlay.)

I've noticed that I get exactly the same spacing problems if I say \only<2>{\leavevmode} instead of changing colors, so presumably what's happening is that the color command is causing a null paragraph to be typeset after the previous nested itemize environment. My question is then how to change the currently active color without contributing any vertical material to the page.

2

I don't know what happens, but the problem seems to be that \only is placed between items. If you insert inside colorized item, there's no change.

In next code I've introduced t option to top align frames and better see where changes start.

\documentclass[10pt]{beamer}

\setbeamersize{text margin left=0pt, text margin right=0pt}
\paperheight=24mm \paperwidth=40mm

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{background}[grid]

\begin{document}

\begin{frame}[t,plain]
\bfseries
\begin{itemize}
  \item Here's a bullet
  \begin{itemize}
    \item And a sub-bullet
  \end{itemize}%
\item \only<2>{\color{red}}This will be blue%
  \begin{itemize}
    \item On overlay 2
  \end{itemize}%
\end{itemize}%
{\color{red}\hrule height .5pt}%
\end{frame}

\end{document}

enter image description here

  • Thanks, but this doesn't really answer my question. If you put the \color in the \item, then you are already in horizontal mode. My goal is to build environments like alertenv but that don't mess up vertical spacing. When you say something like \item<alert@3>, it wraps an environment around the item, so you need to execute the code in internal vertical mode. – user3188445 Jan 21 '16 at 9:41
  • @user3188445 if you add \ifhmode HMODE\fi\ifvmode VMODE\fi after \item (even after \item\only<2>{\color{..}}) you will see that immediately after \item you are in vertical mode. – user4686 Jan 21 '16 at 17:52
  • @jfbu That's the problem. The problem is that \color leaves vertical mode, and \item starts a new paragraph. So \end{itemize} (vertical mode) followed by \color (horizontal mode) followed by \item (vertical mode again) causes unwanted space. I need a way to run \color so it doesn't contribute to the current vertical list. – user3188445 Jan 21 '16 at 21:57
  • 1
    @user3188445 no, \color does not leave vertical mode. It inserts a whatsit and this has implications on vertical spacings in certain circumstances. Search for "color + whatsit". – user4686 Jan 21 '16 at 22:03
  • 1
    @user3188445 bottom of page 5 in your document, sorry. Perhaps an issue of a4 vs usletter. – user4686 Jan 21 '16 at 22:24

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.