2

I am trying to sequentially show the parts of a TikZ drawing made using a \foreach loop.

The code is the following:

\documentclass[beamer]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,calc,fit,shapes}

\begin{document}

        \begin{tikzpicture}  

        \foreach \x in {1,...,6} {
          \visible<\x+2->{
          \node[] at (\x*0.75,0) (n\x) {$\x$};
          \foreach \y in {1,...,\x} {
            \node[] (p\x\y) [below = 0.3 + 0.3*\y of n\x]  {$\bullet$};
          }}}

        \end{tikzpicture}

\end{document}

The problem is that I want the \visible command counter to be delayed two units with respect to the counter \x. And LaTeX does not seem to recognize any of the following syntax:

  • \visible<\x+2>
  • \visible<$\x+2$>
  • \visible<(\x+2)>
  • \visible<$(\x+2)$>

What am I doing wrong?

5

Beamer overlay cannot directly evaluate expressions like \x+2. So you'll have to help it a little bit by adding

\pgfmathtruncatemacro\z{\x+2}

and use \z in specifying the overlay. Also, note that you're missing a positioning library in your preamble.

Code

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{automata,calc,fit,shapes,positioning}

\begin{document}
\begin{frame}
  \begin{tikzpicture}  
  \foreach \x in {1,...,6} {
    \pgfmathtruncatemacro\z{\x+2}
    \visible<\z->{
    \node[] at (\x*0.75,0) (n\x) {$\x$};
    \foreach \y in {1,...,\x} {
      \node[] (p\x\y) [below = 0.3 + 0.3*\y of n\x]  {$\bullet$};
    }}}
  \end{tikzpicture}
\end{frame}
\end{document}

Output

enter image description here

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.