Automatically animate a tikzpicture with "visible on = "

Viewed 1660

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?

1 Answers

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

Related