4

Consider this example:

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}{Slide title}
  \begin{tikzpicture}
    \draw[red, very thick](0, 0) -- (3, 0);
    \onslide<1>{
      \draw(-1, 1) -- (2, 1);
    }
    \onslide<2>{
      \draw(-2, 2) -- (1, 2);
    }
  \end{tikzpicture}
\end{frame}
\end{document}

I have successfully developed an animation using \onslide<>:

enter image description here

However, I would also like to change the slide title when running through the animation. How to do it?

Viesturs
  • 7,895

1 Answers1

5
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\frametitle<1>{Some title}
\frametitle<2>{Another title}
  \begin{tikzpicture}
    \draw[red, very thick](0, 0) -- (3, 0);
    \onslide<1>{
      \draw(-1, 1) -- (2, 1);
    }
    \onslide<2>{
      \draw(-2, 2) -- (1, 2);
    }
  \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

The perhaps simplest option I see is to use an overlay picture in the case the of titles which occupy different amounts of vertical space.

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\frametitle<1>{Some title}
\frametitle<2>{Another title which is very very long and spans two lines
or even more}
  \begin{tikzpicture}[overlay,remember picture,shift={([yshift=-1cm]current page.center)}]
    \draw[red, very thick](0, 0) -- (3, 0);
    \onslide<1>{
      \draw(-1, 1) -- (2, 1);
    }
    \onslide<2>{
      \draw(-2, 2) -- (1, 2);
    }
  \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

An IMHO better solution would be to write the data to the aux file and restore it. This also allows you to work with \pause in tikzpictures without inducing jumps, BTW. However, you do not seem to be interested in such solutions (which is perfectly fine, of course), which is why I am not spelling this out here.