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.

In beamer, is it possible to uncover a sequence of connected line segments drawn in tikz? For example, in the following figure, I want to show the line segments in the third \draw one by one after each -- (except the first one). Is there a way to achieve this, or is it just impossible?

\begin{tikzpicture}[scale=.5]
  \draw[<->,>=latex](0,10)--(0,0)--(10,0)node[below]{$Q$};
  \draw<2-> node[left]at(0,10){$P$} node[below]at(10,0);
  \draw<3->[very thick, red](0,6)--(4,6)--(4,3)--(6.67,3)--(6.67,2)--(9.33,2)--(9.33,0);
\end{tikzpicture}
share|improve this question
    
Instead of posting a “Thank you” as an additional answer, you should thank [user] by upvoting [his/her] answer (with the upward pointing arrow to the left of it; you need 15 reputation points before you can upvote) and accepting it (by clicking on the checkmark). –  Kurt Oct 8 '12 at 0:08

1 Answer 1

up vote 5 down vote accepted

The idea is to use a loop; the obvious choice would be to use \foreach and the remember ... as ... (initially ...) syntax; however, after struggling for over half an hour with fruitless variations of a double-variable use of this syntax, I decided to do a manual version:

\documentclass{beamer}
\usepackage{tikz}

\begin{document}

\begin{frame}
\begin{tikzpicture}[scale=0.5]
\draw<+->[<->,>=latex] (0,10) node[left] {$P$}-- (0,0) -- (10,0) node[below]{$Q$};
\xdef\lastx{0}
\xdef\lasty{6}
\foreach \x/\y in {4/6,4/3,6.667/3,6.667/2,9.33/2,9.33/0}
{
  \draw<+->[very thick,red] (\lastx,\lasty) -- (\x,\y);
  \xdef\lastx{\x}\xdef\lasty{\y}
}
\end{tikzpicture}
\end{frame}

\end{document}

enter image description here

share|improve this answer
    
Hehe, makes me wonder what kind of trouble that automatic solution would be. As I cant pass up a good challenge, I'll have a go at it tomorrow. –  Tom Bombadil Oct 8 '12 at 1:38
    
Hmm, I don't know what your trouble was, but remember= does not seem to remember anything (also see this), I'll fiddle a little more when I get back. –  Tom Bombadil Oct 8 '12 at 9:00
    
@TomBombadil that was exactly the problem; remember= only seems to work in very specific situations, but it mostly doesn't update the \last... values. –  Gonzalo Medina Oct 8 '12 at 14:41
    
Do you think this qualifies as a bug, e.g. something worth reporting to Till Tantau et al.? –  Tom Bombadil Oct 8 '12 at 19:47
    
@TomBombadil yes, I think that it's worth reporting this situation as a bug. Will you be willing to do it? –  Gonzalo Medina Oct 8 '12 at 19:52

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.