3

I'm a little bit lost regarding the inclusion of an animation in my presentation. I have tried to use the animation package, but I am not even close to the desired result.

The animation I would like to have is very simple: a seesaw that is first completely horizontal. Then moves downward (left side of the seesaw higher than the right side). And then horizontal again. These are three moves, which I want to happen when I click my mouse in the presentation.

I made an example of the seesaw in powerpoint, to give a bit of an illustration of the animation (for example, the euro should be higher than the dollar when the seesaw moves). I would like to use this in a formal academic presentation, so any tips regarding the layout are also very welcome! Seesaw bond yield example

  • What can I further do to get some reactions on this post? As I was not even close to a desirable result, I cannot post a MWE. Other suggestions to get more response? – peter Jan 26 '17 at 16:28
  • 5
    It is not clear what the actual problem is (using animate, creating the graphics, etc.). I recommend starting to read the TikZ manual. TikZ allows you to create vector graphics inline (i. e. in the source of your document). Animating is the minor problem then. – AlexG Jan 27 '17 at 16:41
  • 1
    Animations in PDFs depend on the PDF-Viewer. – Schweinebacke Jan 28 '17 at 14:06
  • 1
    Peter, you have the problem, of creating an animated image with LaTeX means, is that true? – Jan Jan 28 '17 at 18:58
  • 1
    What have you tried so far? Having a look at the picture itself, it does not look very hard to get the desired output for one frame of the animation if you have a look at the basics of the tikz package. – epR8GaYuh Jan 29 '17 at 9:52
5
+100
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage{eurosym}

\begin{document}
\begin{frame}
% for animations see beamer documentation page 135f (for version 3.33)
% what I have failed to find in the documentation
% is that the "counter" in \animatevalue may NOT be a LaTeX counter
% but must be TeX count
% regarding the difference see
% https://www.texdev.net/2009/11/17/tex-counts-and-latex-counters/
\newcount\angle
\animate<2-10,12-20>
%\transduration{0}
\newcommand{\maxangle}{-20}
\only<1-10>{\animatevalue<1-10>{\angle}{0}{\maxangle}}
\only<11-21>{\animatevalue<11-20>{\angle}{\maxangle}{0}}
\begin{center}
% https://tex.stackexchange.com/a/18201/120953
\pgfdeclarelayer{bg1}    % declare background layer
\pgfdeclarelayer{bg2}    % declare background layer
\pgfsetlayers{bg2,bg1,main}  % set the order of the layers (main is the standard layer)
\begin{tikzpicture}
    \tikzset{%
        my border style/.style = {
            draw=blue,
            line width=2pt,
        },
        my fill style/.style = {
            fill=blue!50,
        },
        mynodestyle/.style = {
            circle,
            my border style,
            fill,
            minimum size=3em,
            outer sep=0pt,
            transform shape,
        },
    }
    \begin{scope}[rotate=\the\angle]
        \node[mynodestyle, fill=blue!30!white] (euro) at (-2, 0) [above] {\%\euro};
        \node[mynodestyle, fill=red!30!white] (dollar) at (2, 0) [above] {\%\$};
        \begin{pgfonlayer}{bg1}
            \draw[my border style, my fill style] (euro.south) ++(0,5pt) rectangle (dollar.south);
        \end{pgfonlayer}
    \end{scope}
    \begin{scope}[yshift=5pt, scale=1.5]
        \path[my fill style, rounded corners=4pt] (0,0) -- (1,-1) -- (-1,-1) -- cycle;
        \begin{pgfonlayer}{bg2}
            % note how I am using twice the line width because half of the line is overdrawn by the filling
            % if you are very interested in this topic, take a look at this question: https://tex.stackexchange.com/q/29991/120953
            \path[my border style, rounded corners=4pt, line width=4pt,] (0,0) -- (1,-1) -- (-1,-1) -- cycle;
        \end{pgfonlayer}
    \end{scope}
    % ensure the tikzpicture has always the same height
    % by always drawing it (invisibly) for the extreme values additionally.
    % note that with draw=none the border would not be drawn
    % and therefore the picture would be 0.5\pgflinewidth smaller.
    \begin{scope}[rotate=\maxangle]
        \node[mynodestyle, fill=none, draw opacity=0] (euro) at (-2, 0) [above] {};
        \node[mynodestyle, fill=none, draw opacity=0] (dollar) at (2, 0) [above] {};
    \end{scope}
    \node[mynodestyle, fill=none, draw opacity=0] (euro) at (-2, 0) [above] {};
    \node[mynodestyle, fill=none, draw opacity=0] (dollar) at (2, 0) [above] {};
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}

enter image description here

With evince this is playing rather slow, but I suppose that is a matter of the viewer, not the code.

Alternatively one might try to use TikZ to create a gif as shown here and "embed" this with \movie, see beamer documentation section 14.1 Animations.


Animation on a single beamer frame using animate, as requested by the OP; click on the graphicss again to see the second half of the sequence. This requires either A-Reader, Foxit or PDF-XChange viewer:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\usepackage{eurosym}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% command for printing the current BBox coordinates to the terminal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\newcommand\printBoundingBox{{%
    \pgfpointanchor{current bounding box}{south west}%
    \pgfmathparse{\pgf@x/\pgf@xx}%
    \xdef\llx{\pgfmathresult}%
    \pgfmathparse{\pgf@y/\pgf@yy}%
    \xdef\lly{\pgfmathresult}%
    \pgfpointanchor{current bounding box}{north east}%
    \pgfmathparse{\pgf@x/\pgf@xx}%
    \xdef\urx{\pgfmathresult}%
    \pgfmathparse{\pgf@y/\pgf@yy}%
    \xdef\ury{\pgfmathresult}%
    \typeout{+++BoundingBox: (\llx,\lly)\space(\urx,\ury)+++}
}}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% see-saw ; graphic with parameter (angle)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\seesaw[1]{ %#1: angle
  \begin{tikzpicture}
      \useasboundingbox (-2.5843,-1.00703) rectangle (2.73778,1.89165);
      \tikzset{%
          mynodestyle/.style = {
              circle,
              draw=black,
              fill,
              minimum size=3em,
              transform shape,
          }
      }
      \begin{scope}[rotate=#1]
          \node[mynodestyle, fill=blue!.3!white] (euro) at (-2, 0) [above] {\%\euro};
          \node[mynodestyle, fill=red!.3!white] (dollar) at (2, 0) [above] {\%\$};
          \draw (euro.south) -- (dollar.south);
      \end{scope}
      \draw[] (0,0) -- (1,-1) -- (-1,-1) -- cycle;
      \node[mynodestyle, fill=none, draw=none] (euro) at (-2, 0) [above] {};
      \node[mynodestyle, fill=none, draw=none] (dollar) at (2, 0) [above] {};
      \printBoundingBox
  \end{tikzpicture}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
  \begin{center}
  \begin{animateinline}[controls]{12}
    \multiframe{21}{iAngle=0+-1}{ % 0, -1, ...,-20
      \seesaw{\iAngle}
    }
    \newframe* %Pause; click to continue
    \multiframe{20}{iAngle=-19+1}{ % -19, -18, ..., 0
      \seesaw{\iAngle}
    }
  \end{animateinline}
  \end{center}
\end{frame}  

\end{document}

enter image description here

  • This is indeed what I intended! I gues the separate pages will at some point turn into one animation? I would really appreciate it if you could make this even nicer :) I will take a more detailed look at your code tomorrow, as I of course want to learn to make these things myself. – peter Jan 30 '17 at 23:30
  • 1
    The separate pages are the way beamer does animations. It plays them automatically with a given speed but this also depends on the pdf viewer. The beamer documentation gives you more explanation. – JLo0815 Jan 31 '17 at 8:11
  • 1
    The bounding box changes between animation frames. I took the liberty to add a macro that prints the current BBox coordinates to the terminal. These can be used to set the same BBox for all frames ( \useasboundingbox (...,...) rectangle (...,...);. Moreover I added a version that makes use of the animate package. After all, it is you, @jakun, who deserves the bounty. – AlexG Jan 31 '17 at 10:30
  • @AlexG thanks. I have just installed Foxit Reader Version 2.3.0 but I can not find the button to enter fullscreen mode... I have tried F5 (which does the trick in evince) and F11 (which I have read online for Foxit) but nothing happened. – jakun Jan 31 '17 at 16:45
  • @AlexG I have figured out why the size of the TikZ picture was changing in my first attempt: I tried to draw the see-saw always additionall invisibly at the extreme positions. But with \draw=none the border was not drawn and thus .5\pgflinewidth were missing. I like your idea of saving the bounding box (although I am a little surprised it looks so complicated) but I think it's good to show several different options. Therefore I am using my first approach again in my example and have moved your macro to your example. – jakun Jan 31 '17 at 19:30

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.