Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to reuse part of an animated TikZ figure in beamer. Before switching to TikZ, I built PDF animations with IPE, and could select specific pages in the \includegraphics{} command. To do the same in TikZ, my approach would be to generate standalone tikz figures in PDFs and do the same as before. I'm wondering whether there is a more intelligent way that avoids the need for multiple files.

Note that the \againframe{} command won't help, since I want to have other content on the slide with the repeated animation as well.

Here is a minimal example:

\documentclass{beamer}
\usepackage{tikz}
\tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    alt/.code args={<#1>#2#3}{%
        \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    }}
\begin{document}
    \begin{frame}{test}
        This is the first frame, which contains an animation:
        \begin{tikzpicture}
            \node[rectangle](a){A}; 
            \node[rectangle,visible on=<2>] (b) at (0, 2) {B};
            \draw[->,visible on=<2>] (a) -- (b);
        \end{tikzpicture}
    \end{frame}
    \begin{frame}{test2}
        This is the second frame, which should include the figure from the 1st, 
        but only the final, i.e. second part of the animation.

        % ....?
    \end{frame}
\end{document}
share|improve this question
    
Is there a specific reason you want to refrain from the standalone approach? I have tried a couple of things in my life with beamer, but still find generating a multipage PDF from a standalone TiKZ figure to be included in a foreach loop with includegraphics (so that I can easily the number of animation steps, especially in handout mode) to be the most elegant and flexible approach. –  Daniel Sep 18 '13 at 22:02
    
I went for the standalone/beamer approach in the meantime, which is decent. The main issue I have with it is that the "slide" in the standalone has its own independent ordering (which can be slightly confusing, inconsistent) and it is not easy to make TikZ interact with surrounding text. Can you elaborate on how you combine foreach with handout mode? –  hannes Sep 23 '13 at 12:14

1 Answer 1

A very simple solution is to put your tikzpicture in a macro definition and call it multiple times:

\newcommand{\myanimation}{\begin{tikzpicture}...your code here}

\begin{frame}{test}
    This is the first frame, which contains an animation:
    \myanimation
\end{frame}
\begin{frame}{test2}
    This is the second frame, which should include the figure from the 1st, 
    but only the final, i.e. second part of the animation.
    \myanimation
\end{frame}

This allows you to even introduce parameters so you can have slight variations in the second instance, say some captions change or you want different styles installed.

Another, less flexible, solution is to put your tikzpicture code into a myanimation.tex file and include it with \input{myanimation} when needed.

Note that both solutions are beamer-agnostic and will insert the full animation every time.

share|improve this answer
    
Your last sentence was the deal-breaker for that idea. Usually I don't want to reproduce a multi-step presentation completely, but a specific (usually the final) one (see original post) –  hannes Sep 23 '13 at 12:17
    
I see what you mean. Unfortunately my knowledge of beamer's internals is not good enough to bake a version of \againframe that only repeats a portion of a frame. If anybody could, I would find it useful too. –  Bordaigorl Sep 24 '13 at 10:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.