3
\documentclass[xcolor=table ]{beamer}


\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}

\title[Your Short Title]{Your Presentation}
\author{You}
\institute{Where You're From}
\date{Date of Presentation}

\begin{document}


\begin{frame}{Introduction}

\begin{itemize}
  \item <1-> Your introduction goes here!
  \item <2> Use \texttt{itemize} to organize your main points.
\end{itemize}

\end{frame}
\begin{frame} 
\begin{itemize}
  \item Your introduction goes here!
  \item {\colorbox{yellow} {Use \texttt{itemize} to organize your main points.}}
\end{itemize}

\end{frame}

\end{document}

This MWE showed itemized list. After two sequential items are displayed, I expect the second item to be highlighted in a third step. I achieved this by duplicating frame. Can this be achieved by overlay without manual duplication of frame

1 Answer 1

5

The easy solution is to use \only to make the \colorbox{yellow} part of the code conditional:

    \begin{frame}{Introduction}
        \begin{itemize}
            \item <1-> Your introduction goes here!
            \item <2-> \only<3>{\colorbox{yellow}}{Use \texttt{itemize} to organize your main points.}
        \end{itemize}
    \end{frame}

However, there's an issue with this: Because \colorbox fills some area around the text, it changes the spacing, which leads to visible jumping (try it out to see it).

One can fix this by always using a \colorbox, but fill it with the background color when it should not be highlighted. As this is a bit messy, I would define a new command for this purpose:

\documentclass[xcolor=table]{beamer}
\usepackage[english]{babel}

\title[Your Short Title]{Your Presentation}
\author{You}
\institute{Where You're From}
\date{Date of Presentation}

\newcommand<>{\mycolorbox}[3][white]{{%
    % #1 = default color when overlay specification is not fulfilled (default: white)
    % #2 = color when overlay specification is fulfilled
    % #3 = text to be displayed
    % #4 = the actual overlay specification
    \def\mycolor{#1}%
    \only#4{\def\mycolor{#2}}%
    \colorbox{\mycolor}{#3}%
}}

\begin{document}
    \begin{frame}{Introduction}
        \begin{itemize}
            \item <1-> Your introduction goes here!
            \item <2-> \mycolorbox<3>{yellow}{Use \texttt{itemize} to organize your main points.}
        \end{itemize}
    \end{frame}
\end{document}

The syntax for \newcommand<> is explained in beamer's user guide, section 9.6.1 Making Commands and Environments Overlay Specification-Aware. The first argument is the name of the macro to be defined (\mycolorbox in this case), then follows the number of arguments excluding the overlay specification, and finally there's the default value for the first argument. Inside the command, the arguments can be referred to using the # character followed by their number (#1, #2 and so on, see the comments).

The double pair of braces {{ and }} exists to create a TeX group, which means that any macro (re)definitions will be forgotten at the end. The outer pair delimits the the contents of the command, while the inner pair is the TeX group.

I then use \def (I could have also used \newcommand) to define a new macro, \mycolor, which is initially the default color. Using \only, I then conditionally redefine it to the desired color (yellow in this example). Finally, I call the \colorbox command.

By the way, it is also possible to just write \colorbox<3>{yellow}{text}, but for some reason this uses a black background...

2
  • Can you please explain the syntax for creating new command
    – Vaibhav
    Mar 23, 2016 at 12:37
  • @Vaibhav: See my edit, I hope it makes things a bit clearer.
    – wrtlprnft
    Mar 23, 2016 at 12:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .