4

Suppose I have a loop:

\begin{tikzpicture}
  \foreach \frm \in {1,...,6}{ \only<\frm>{
    % if \frm > 4: set \x to 1, 0 otherwise
    \node (foo) at (10+5*\x,7) {hello};
  }}
\end{tikzpicture}

I want to "move" the node at a given slide, but I'm struggling to find a suitable way to express the conditional in the comment in TeX.


Edit: I tried \ifthenelse to no avail:

\node (foo) at (10+5*\ifthenelse{\frm<5}{0}{1},7) {hello};

Gives me this error, which I cannot parse at all

! Use of \beamer@only doesn't match its definition.
\new@ifnextchar ...served@d = #1\def \reserved@a {
                                                  #2}\def \reserved@b {#3}\f...
5

The following hack should do the trick. I modified the coordinates a bit so they'd stay on the screen.

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}[fragile]
\begin{tikzpicture}
  \foreach \frm in {1,...,6}{
    \draw (0,0) node {origin};
    \only<\frm>{
    % if \frm > 4: set \x to 1, 0 otherwise
    \ifnum\frm>4\relax\def\x{1}\else\def\x{0}\fi%
    \node (foo) at (5+5*\x,7) {hello};
  }}
\end{tikzpicture}
\end{frame}

\end{document}
6

I don't know why you are doing it and also I am guessing that this goes in a beamer presentation so the following seems to do what you might want.

\documentclass{beamer}
    \usepackage{tikz}
    \begin{document}

\begin{frame}{title}
    \begin{tikzpicture}
    \foreach \frm in {1,...,6}{ 
    \onslide<\frm>{
    % if \frm > 4: set \x to 1, 0 otherwise
    \pgfmathparse{\frm > 4? 1 : 0}
    \node (foo) at (10 + 5*\pgfmathresult,7) {hello};
        }
    }
\end{tikzpicture}
\end{frame}
\end{document}

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.