Discussion:
Overlays in Beamer Tikz giving Errors
(too old to reply)
f***@gmail.com
2020-04-12 08:54:29 UTC
Permalink
My tikz figure is working perfectly within beamer. But I need to draw an arrow on slide two. Whenever I insert \only<2> or \onslide<2> within THIS tikz picture, it gives error:

\begin{frame}[t]{Example 3.2}
\Large $L = \lbrace w\#w | w \in \lbrace 0,1 \rbrace^* \rbrace$ \normalsize
\vspace{2cm}
\begin{center}
\begin{tikzpicture}[->, >=stealth', shorten >= 1pt, node distance = 0.6cm, semithick]
\begin{scope}
\newcounter{prevI}\setcounter{prevI}{0}
\node(n0) at (0,0){};
\foreach \x [count=\i] in {0,1,1,0,0,0,\#,0,1,1,0,0,0,$\sqcup$}{
\node[right of = n\theprevI,minimum size=0.6cm] (n\i) {\x};
\stepcounter{prevI}
}
\node[right of= n\theprevI]{$\cdots$};
\end{scope}

%\only<2>{
\draw [->] (0,1) -| (n1);
%}
\end{tikzpicture}
\end{center}
\end{frame}


This compiles perfectly fine, even draws the arrow on the current slide correctly. BUT when I uncomment the \only<2> at the bottom, Latex compiler gives me errors:


line 145: Command \***@prevI already defined. \end{frame}
line 95: You need to compile with XeLaTeX or LuaLaTeX to use the Fira fonts
line 14: Snakes have been superseded by decorations. Please use the decoration libraries instead of the snakes library
line 66: Overfull \vbox (50.88618pt too high) detected
line 66: Overfull \vbox (15.63992pt too high) detected
: Label(s) may have changed. Rerun to get cross-references right.
samcarter8
2020-04-12 10:03:31 UTC
Permalink
The problem is that if the frame is executed in more than one overlay,
the counter `prevI` would also be created more than once. This problem
can be avoided by creating it outside of the frame.

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{arrows}


\begin{document}

\newcounter{prevI}
\begin{frame}[t]{Example 3.2}
\Large $L = \lbrace w\#w | w \in \lbrace 0,1 \rbrace^* \rbrace$ \normalsize
\vspace{2cm}
\begin{center}
\begin{tikzpicture}[->, >=stealth', shorten >= 1pt, node distance =
0.6cm, semithick]
\begin{scope}
\setcounter{prevI}{0}
\node(n0) at (0,0){};
\foreach \x [count=\i] in {0,1,1,0,0,0,\#,0,1,1,0,0,0,$\sqcup$}{
\node[right of = n\theprevI,minimum size=0.6cm] (n\i) {\x};
\stepcounter{prevI}
}
\node[right of= n\theprevI]{$\cdots$};
\end{scope}

\draw<2> [->] (0,1) -| (n1);

\end{tikzpicture}
\end{center}
\end{frame}

\end{document}
Post by f***@gmail.com
\begin{frame}[t]{Example 3.2}
\Large $L = \lbrace w\#w | w \in \lbrace 0,1 \rbrace^* \rbrace$ \normalsize
\vspace{2cm}
\begin{center}
\begin{tikzpicture}[->, >=stealth', shorten >= 1pt, node distance = 0.6cm, semithick]
\begin{scope}
\newcounter{prevI}\setcounter{prevI}{0}
\node(n0) at (0,0){};
\foreach \x [count=\i] in {0,1,1,0,0,0,\#,0,1,1,0,0,0,$\sqcup$}{
\node[right of = n\theprevI,minimum size=0.6cm] (n\i) {\x};
\stepcounter{prevI}
}
\node[right of= n\theprevI]{$\cdots$};
\end{scope}
%\only<2>{
\draw [->] (0,1) -| (n1);
%}
\end{tikzpicture}
\end{center}
\end{frame}
Loading...