Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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...
share|improve this question

2 Answers 2

up vote 5 down vote accepted

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}
share|improve this answer
    
Awesome, that does the trick. Thanks. –  bitmask Feb 29 '12 at 12:07

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.