1

I'd like to put some text (actually a figure) right next to an overprint environment (e.g., containing a listing). To that end, I have set the optional argument of the environment to use less space than the whole line (the default). However, apparently there is a fixed line break at the end of the environment or something to that effect(?). Is there an easy fix or do I have to resort to columns or tabulars? Edit: Why does adding a \textwidth-wide rule before the environment "fix" the problem!? Also, how to decrease the space between overprint environments (without manual intervention like \vspace{-somelength})? Edit: The matter becomes even worse when listings are involved: using \onslide with braces completely hides the listing.

\begin{filecontents*}{file.c}
int foo = 42;
\end{filecontents*}

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\begin{document}
\begin{frame}{}
    % \rule{\textwidth}{1pt}
    \begin{overprint}[0.5\textwidth]
      \onslide<1|handout:0>\lstinputlisting[frame=tlrb]{file.c}%
      % \onslide<2|handout:0>{\lstinputlisting[frame=tlrb]{file.c}}% completely lost *and* increasing vspace *shruggle*
      \onslide<3|handout:0>{}
    \end{overprint}\includegraphics[width=0.25\linewidth,keepaspectratio]{example-image}\\
    \rule{\textwidth}{1pt}
  \end{frame}
\end{document}

The image should be in the same line as 1 and 2 on all 3 slides.

1

The root of the problem is missing {} to denote the content of \onslide. Especially the last one without anything needs an empty {}.

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\begin{document}
  \begin{frame}{}
    % \rule{\textwidth}{1pt}
    \begin{overprint}[0.5\textwidth]
      \onslide<1|handout:0>{1}%
      \onslide<2|handout:0>{2}%
      \onslide<3|handout:0>{}%
    \end{overprint}bla
    \rule{\textwidth}{1pt}
  \end{frame}
\end{document}

I would go the easy way and use columns:

\documentclass{beamer}

\begin{document}
  \begin{frame}{}
    \begin{columns}[onlytextwidth]
            \begin{column}{.45\textwidth}
      \only<1|handout:0>{1}%
      \only<2|handout:0>{2}%
      \only<3|handout:0>{3}%
            \end{column}
            \begin{column}{.45\textwidth}
                \includegraphics[width=\textwidth]{example-image}
            \end{column}            
    \end{columns}
    \rule{\textwidth}{1pt}
  \end{frame}
\end{document}
  • I had to remove the braces from the \onslide calls because else the listings I want to use there are completely eaten (without knowing this complicated things even more). I think removing the braces is actually the correct way because \onslide works similar to items and it is documented like that as well. But your example shows that this is problematic too. I agree with you that it is better to just use columns... I'd still like to know what's the cause... possible some bug within either package. I'll not mark this answer as accepted. – stefanct Aug 9 '18 at 1:05
  • 1
    @stefanct In this case I'm not sure if this problem is really related to overprint/onslide. Try \begin{frame}{} \lstinputlisting[frame=tlrb,linewidth=.4\textwidth]{file.c}% \includegraphics[width=0.25\linewidth]{example-image}% \end{frame} – user36296 Aug 9 '18 at 12:51

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.