The apparently odd phenomenon can be explained examining the following simple example:
\documentclass{beamer}
\newcommand\showpauses{The value of beamerpauses at this point in slide \insertpagenumber\ is: \thebeamerpauses}
\begin{document}
\begin{frame}{Test}
\only<1-2>{\par\showpauses%
\begin{enumerate}[<+->]
\item One \showpauses
\item Two \showpauses
\end{enumerate}
}
\only<3>{\par\showpauses}
\end{frame}
\end{document}
After processing the document you'll have a three slide presentation showing the value of the beamerpauses
counter at different stages.
Up to slide two, everything goes as one would expect: at the end of the enumerate
on slide two the value of beamerpauses
is three; however, on slide three, beamerpauses
is 1
. Why happened this? Well, because the overlay specification for \only
was 1-2
, so everything happening on slides 1 and 2 will occur only for those slides; in particular, the stepping of beamerpauses
produced by the enumerate will have effect only for slides one and two. In the third slide, which is not under the effect of the \only
, the counter beamerpauses
will have the value that it had before.
Is this showing something wrong with beamer
? I don't think so; after all, the expected meaning of \only
is to keep things under its scope only for the specified slides.
If you use <1->
(or <1-3>
) instead of <1-2>
in the above example, as in
\documentclass{beamer}
\newcommand\showpauses{The value of beamerpauses at this point in slide \insertpagenumber\ is: \thebeamerpauses}
\begin{document}
\begin{frame}{Test}
\only<1->{\par\showpauses%
\begin{enumerate}[<+->]
\item One \showpauses
\item Two \showpauses
\end{enumerate}
}
\only<3>{\par\showpauses}
\end{frame}
you'll see that now on slide three the counter has the value three, because the third slide is under the scope of \only
.
The "dirty" manual increment of the counter in the original example was simply due to the special effect the OP wanted to achieve. Perhaps this same effect could be achieved in another way, without manual intervention?
I am definitely unfamiliar with both beamer
and tikz
(do not quite get what the \only
are supposed to do) but perhaps this could go in the direction you want:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\newcounter{count}
% helper macro:
\long\def\GobToSemiColon #1;{}
\newcommand\myPicture{
\begin{tikzpicture}
\begin{scope}[start chain = going below]
\ifnum\value{count}<1 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>3 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is between
1 and 3};
\ifnum\value{count}>-1 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is
negative};
\ifnum\value{count}<100 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>200 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only if counter is between
100 and 200};
\ifnum\value{count}<3 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>20 \expandafter\GobToSemiColon\fi
\node[draw, circle, on chain] {only when counter is in the range 3 to 20};
\end{scope}
\end{tikzpicture}
}
\begin{document}
\begin{frame}
\only{\setcounter{count}{-3}\myPicture}
\only{\setcounter{count}{105}\myPicture}
\only{\setcounter{count}{39}\myPicture}
\only{\setcounter{count}{2}\myPicture}
\only{\setcounter{count}{5}\myPicture}
\end{frame}
\end{document}
![beamer](https://i.stack.imgur.com/h1oev.png)
Best Answer
You were near: the counter is called
framenumber
. There's an easier way to branch for numeric cases.An easier way for extending the number of colors is using
xparse
; you just call\assigncolors{red,green,blue}
or with any other list. You can issue this command any times you want during the document, but it's better to do it outside frames, to avoid multiple evaluations.