2

I'm using beamer and I'm trying to automatically animate a graphic constructed in a single frame with tikzpicture. I would like to make a loop where the lines with visible on=<1> and visible on=<2> appear automatically without clicking and one after another (<1> then <2> then <1> then <2> ... infinite loop).

Here is my Latex code:

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usetheme{Madrid}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{animate}
\begin{document}
\begin{frame}
\begin{center}
\begin{tikzpicture}[auto]
    \draw(-2.7,1.5) node[sloped,above] {Start A};
    
    \draw[->,thick] (-2,0.5)  -- node[below] {T} (4,0.5) ;
    
    \draw[visible on=<1>,gray1,-,thick,dashed] (-1.7,1.7)  -- (3.7,1.7);
    \draw[visible on=<1>] (1,1.8) node[sloped,above] {text};
    
    \draw[visible on=<2>,gray1,-,thick,dashed] (-1.7,1.7)  -- (-0.3,1.7);
    \draw[visible on=<2>,gray1,-,thick,dashed] (2.3,1.7)  -- (3.7,1.7); 
    \draw[visible on=<2>](3,2.5) node[sloped,above] {text};
    \draw[visible on=<2>](1,1.68) node[sloped,above] {Point};
    \draw[visible on=<2>](1,1.18) node[sloped,above] {C};
    
    \draw(4.7,1.90) node[sloped,above] {Point};
    \draw(4.7,1.45) node[sloped,above] {B};
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}

This gives me the following two slides without automatic that are not automatically animated:

enter image description here

I searched for answers to my question and found this answer.

I added this following command \usetikzlibrary{shapes,arrows, positioning, calc} \usetikzlibrary{overlay-beamer-styles} to the preamble but it did not solve my problem.

\setbeamercovered{dynamic}
\usetikzlibrary{shapes,arrows, positioning, calc}  
\usetikzlibrary{overlay-beamer-styles}
 

Do you have a suggestion for creating this animation loop?

Ph.D.Student
  • 704
  • 6
  • 27

1 Answers1

1

You can use \transduration{<number of seconds>} to automagically switch between the transitions without clicking (needs a pdf viewer which supports transitions, e.g. adobe reader in presentation mode).

\documentclass{beamer}

\usetheme{Madrid}
\usepackage{tikz}
\usetikzlibrary{positioning}
\setbeamercovered{dynamic}
\usetikzlibrary{shapes,arrows, positioning, calc}  
\usetikzlibrary{overlay-beamer-styles}


\begin{document}

\newcommand{\myani}{1-}

\begin{frame}[label=foo]
\transduration<\myani>{1}
\begin{center}
\begin{tikzpicture}[auto]
    \draw(-2.7,1.5) node[sloped,above] {Start A};
    
    \draw[->,thick] (-2,0.5)  -- node[below] {T} (4,0.5) ;
    
    \draw[visible on=<1>,gray,-,thick,dashed] (-1.7,1.7)  -- (3.7,1.7);
    \draw[visible on=<1>] (1,1.8) node[sloped,above] {text};
    
    \draw[visible on=<2>,gray,-,thick,dashed] (-1.7,1.7)  -- (-0.3,1.7);
    \draw[visible on=<2>,gray,-,thick,dashed] (2.3,1.7)  -- (3.7,1.7); 
    \draw[visible on=<2>](3,2.5) node[sloped,above] {text};
    \draw[visible on=<2>](1,1.68) node[sloped,above] {Point};
    \draw[visible on=<2>](1,1.18) node[sloped,above] {C};
    
    \draw(4.7,1.90) node[sloped,above] {Point};
    \draw(4.7,1.45) node[sloped,above] {B};
\end{tikzpicture}
\end{center}
\end{frame}

\foreach \x in {0,...,10}{
\againframe{foo}
}

\renewcommand{\myani}{1}
\againframe{foo}

\begin{frame}
content
\end{frame}
\end{document}

enter image description here

  • Thank you for your reply, I added the commendation \transduration{1} and it works. But once the animation is finished, it goes directly to the next slide. I would like the animation to loop: <1> then <2> then <1> then <2>... without automatically going to the slide. – Ph.D.Student Jun 03 '21 at 16:12
  • @Ph.D.Student You can restrict the reach with something like `\transduration<1-2>{1}` to avoid it going to the next slide. For repeating the frame, have a look at `\againframe` – samcarter_is_at_topanswers.xyz Jun 03 '21 at 16:14
  • Thanks for your suggestion, I saw an example on \againframe https://tex.stackexchange.com/questions/113832/tikz-beamer-highlight-different-nodes-in-presentation-using-againframe . If I want to have an infinite loop (ie, if I stay on the same slide <1> appears then <2> then <1> ... (a loop), so I have to create an infinite number of \againframes ? – Ph.D.Student Jun 03 '21 at 16:25
  • Also, I have tried \transduration<1-2>{1} to avoid going to the next slide and it doesn't work for me. Thank you. – Ph.D.Student Jun 03 '21 at 16:39
  • 1
    @Ph.D.Student Sorry, my bad: `\transduration<1>{1}` to avoid the transition after the second overlay – samcarter_is_at_topanswers.xyz Jun 03 '21 at 16:45
  • Yes, it works with \transduration<1>{1} thanks. I still can't solve the animation loop problem. – Ph.D.Student Jun 03 '21 at 16:49
  • @Ph.D.Student I added an example which loops 12 times over the animation before it stops before the next frame – samcarter_is_at_topanswers.xyz Jun 03 '21 at 17:02
  • Thank you! The problem is that each loop is created in a separate slide and that means the loop does not repeat in the same slide. So, I end up with several slides instead of one slide with an infinite loop. – Ph.D.Student Jun 03 '21 at 17:11