3

I want to draw a complete graph with tikZ. At first the nodes, then the lines of the first node to the others, then the lines of the second node to the remaining and so forth. All these steps work with foreach-loops and each single drawing should appear step-by-step with the beamer function \visible<..>. My idea was to use a global LaTeX-counter to count all steps over all foreach-loops.

\documentclass[10pt,ngerman]{beamer}
\usepackage{tikz}
\newcounter{steps}
\begin{document}

\begin{frame}{Complete Graph}
    \begin{tikzpicture}[
        kreis/.style={circle, draw, minimum size=1.5cm},
        ]

        \foreach [count=\i] \letter in {A,...,F}{%
%           \stepcounter{steps}
            \visible<\thesteps->{%
                \node [kreis] (\letter) at (\i*60+30:2.5) {\huge{\letter}};
                }
            }
           \end{tikzpicture}
    \end{frame}
\end{document}

The MWE compiles, but when I remove the comment, then texmaker runs in an endless loop. Why? enter image description here

1 Answer 1

4

You always increase the counter to a value that one more slide gets inserted because the slide gets "executed" several times. The beamer class has a command for such situations, \resetcounteronoverlays. Using this command fixes your problem.

\documentclass[10pt,ngerman]{beamer}
\usepackage{tikz}
\newcounter{steps}
\resetcounteronoverlays{steps}
\begin{document}

\begin{frame}{Complete Graph}
    \begin{tikzpicture}[
        kreis/.style={circle, draw, minimum size=1.5cm},
        ]

        \foreach [count=\i] \letter in {A,...,F}{%
           \stepcounter{steps}
            \visible<\thesteps->{%
                \node [kreis] (\letter) at (\i*60+30:2.5) {\huge{\letter}};
                }
            }
           \end{tikzpicture}
    \end{frame}
\end{document}

However, I would draw this differently anyway.

\documentclass[10pt,ngerman]{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}
\begin{document}

\begin{frame}{Complete Graph}
    \begin{tikzpicture}[
        kreis/.style={circle, draw, minimum size=1.5cm},
        ]

        \foreach [count=\i] \letter in {A,...,F}{%
           {%
               \node[visible on=<\i->] [kreis] (\letter) at (\i*60+30:2.5) {\huge{\letter}};
                }
            }
     \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

2
  • You are right with your hint to use \i instead of the global counter, I had this in the beginning, but there are more foreach-loops to follow and I want to use the \i in the same way in all other foreach-loops. Anyhow, many thanks for answering my question so quickly. Commented Dec 7, 2019 at 17:27
  • @HaraldLichtenstein You're welcome! You can use a counter, just add \resetcounteronoverlays{steps}.
    – user194703
    Commented Dec 7, 2019 at 17:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .