Using \only in beamer presentation

57,703

Your aim seems to be to present several different policies, while leaving the general description of the first two items as a constant. You can use a combination of \alt and \only `:

\documentclass{beamer}

\begin{document}

\begin{frame}[t]
\frametitle{Heuristic Policies}

\begin{columns}

\column{0.5\textwidth}
\begin{itemize}
\item<1-> These are methods aiming to give a good but not necessarily optimal solution to a problem.
\item<2-> There exist a number of such policies for bandit problems.
\alt<1-9>{
\item<3-9> Greedy policy:
\begin{itemize}
\normalsize
\item<4-9> choose arm with greatest expected reward
\item<5-9> ignores variability in prior distribution
\item<6-9> quite good for Bernoulli bandits, but less effective for normal bandits
\end{itemize}
}{\only<10-14>{\item<10-> Next policy:
\begin{itemize}
\normalsize
\item<11-14> comment 1
\item<12-14> comment 2
\item<13-14> comment 3\par
\rule{0pt}{2.7cm}
\end{itemize}}
\only<15-18>{\item<15-> Another policy:
\begin{itemize}
\normalsize
\item<16-18> Another comment 1
\item<17-18> Another comment 2
\item<18-18> Another comment 3\par
\rule{0pt}{2.7cm}
\end{itemize}}
}
\end{itemize}

\column{0.3\textwidth}
\vspace{-25pt}
\uncover<7->{\begin{figure}
\begin{center}
\includegraphics[height = 2.7cm, trim=-1cm 0cm 0cm 0cm,clip=true,width=3cm]{example-image-a}
\caption*{$(\alpha,\beta) = (1,1)$}
\end{center}
\end{figure}}
\vspace{-25pt}
\uncover<8->{
\begin{figure}
\begin{center}
\includegraphics[height = 2.7cm, trim=-1cm 0cm 0cm 0cm,clip=true,width=3cm]{example-image-a}
\caption*{$(\alpha,\beta) = (6,5)$}
\end{center}
\end{figure}}

\column{0.2\textwidth} 
\only<9>{$\Rightarrow$ play this arm} 
\only<13-14>{$\Rightarrow$ play this arm with probability $\varepsilon$\vspace{80pt}} 
\only<14>{$\Rightarrow$ play this arm with probability $1-\varepsilon$} 
\end{columns} 
\onslide<10>{\null}
\end{frame}

\end{document}

To avoid the jumping of the first common two items I used some "invisible" rules.

An animated image of the resulting document:

enter image description here

Share:
57,703

Related videos on Youtube

lokodiz
Author by

lokodiz

Updated on June 26, 2022

Comments

  • lokodiz
    lokodiz less than a minute

    I have the following code for a slide from a presentation:

    \begin{frame}
    \frametitle{Heuristic Policies}
    \begin{columns}
    
    \column{0.5\textwidth}
    \begin{itemize}
    \item<1-> These are methods aiming to give a good but not necessarily optimal solution to a problem.
    \item<2-> There exist a number of such policies for bandit problems.
    \only<1-9>{
    \item<3-9> Greedy policy:
    \begin{itemize}
    \normalsize
    \item<4-9> choose arm with greatest expected reward
    \item<5-9> ignores variability in prior distribution
    \item<6-9> quite good for Bernoulli bandits, but less effective for normal bandits
    }
    \end{itemize}
    
    \end{itemize}
    
    
    \column{0.3\textwidth}
    
    \vspace{-25pt}
    \uncover<7->{\begin{figure}
    \begin{center}
    \includegraphics[height = 2.7cm, trim=-1cm 0cm 0cm 0cm,clip=true]{bandit.jpg}
    \caption*{$(\alpha,\beta) = (1,1)$}
    \end{center}
    \end{figure}}
    \vspace{-25pt}
    \uncover<8->{
    \begin{figure}
    \begin{center}
    \includegraphics[height = 2.7cm, trim=-1cm 0cm 0cm 0cm,clip=true]{bandit.jpg}
    \caption*{$(\alpha,\beta) = (6,5)$}
    \end{center}
    \end{figure}}
    
    
    \column{0.2\textwidth}
    
    \uncover<7->{$\mu = \frac{1}{2}$}\\
    \vspace{70pt}
    \uncover<8->{$\mu = \frac{6}{11}$}\\
    \only<9>{$\Rightarrow$ play this arm}
    
    
    \end{columns}
    \end{frame}
    

    At the moment, it's doing what I want. However, the next step is to have it so that all of the bullets from "Greedy policy" are removed as well as "play this arm", and the bulleted text replaced by similar text formatted in the same way. However, I can't see to use \only to do what I want. I tried:

    ...
    
    \item<4-9> choose arm with greatest expected reward
    \item<5-9> ignores variability in prior distribution
    \item<6-9> quite good for Bernoulli bandits, but less effective for normal bandits
    }
    \end{itemize}
    
    \only<10-16>{
    \item<10-16> Next policy:
    \begin{itemize}
    \normalsize
    \item<11-16> comment 1
    \item<12-16> comment 2
    \item<13-16> comment 3
    }
    \end{itemize}
    
    \end{itemize}
    
    \column{0.3\textwidth}
    
    ...
    

    but this didn't work. Could anyone show me what I'm doing wrong? Thanks.

  • lokodiz
    lokodiz almost 9 years
    Thanks, that worked really well. However, I have another problem (which I anticipated I might have). I currently have for my final column: \column{0.2\textwidth} \only<13-14>{$\Rightarrow$ play this arm with probability $\varepsilon$} \vspace{80pt} \only<9>{$\Rightarrow$ play this arm} \only<14>{$\Rightarrow$ play this arm with probability $1-\varepsilon$} \end{columns} \onslide<10>{\null} \end{frame} However, this causes the line "play this arm" to be split over two (very far apart) lines. How could I remedy this?
  • Gonzalo Medina
    Gonzalo Medina almost 9 years
    @SimonC please see my updated answer (simply put the overlays in "natural" ascending order). Also, don't forget that you can mark the answer that solved your problem as accepted by clicking the checkmark to its left. More information in How do you accept an answer?.
  • Gonzalo Medina
    Gonzalo Medina almost 9 years
    @SimonC Ah, no. I see that the problem persists (it only moved to another place). I'll think about this and let you know.
  • Gonzalo Medina
    Gonzalo Medina almost 9 years
    @SimonC Problem solved! The key was to include the \vspace inside the overlay specification. I wasn't sure about the exact vertical positioning for the texts in the right-most column, but you can adjust them according to your needs.
  • lokodiz
    lokodiz almost 9 years
    Hmm, I'm still having an issue. "play this arm" appears to the right of the top image, whilst I want it to the right of the bottom image. I tried \only<9>{\vspace{80pt} $\Rightarrow$ play this arm} and putting the vspace outside of the \only, but it all this does is cause a large break between the two lines. And thanks a lot for your help; I've accepted your answer now :)
  • Gonzalo Medina
    Gonzalo Medina almost 9 years
    @SimonC use \only<9>{\vspace*{80pt}\par$\Rightarrow$ play this arm}. Thanks for accepting the answer :-)
  • lokodiz
    lokodiz almost 9 years
    That seems to work, thanks. What exactly does the inclusion of an asterisk do to modify the behaviour?
  • Gonzalo Medina
    Gonzalo Medina almost 9 years
    @SimonC the relevant part is the use of \par not the star in \vspace. The difference between \vspace* and \vspace is that \vspace* is not ignored at the beginning of a page (perhaps in this case it's also enough to use \vspace).