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.

Is there a way to uncover arrows in an xymatrix? Usually when I have problems with \uncover I use multiple frames, but I would like to be able to do this on a single frame.

Here is a sample: I would like the first slide to read "B", and then uncover "A →". The following code doesn't cover the "→".

\documentclass{beamer}
\usepackage[all]{xy}    

\begin{document}

\begin{frame}[plain]

\xymatrix{
\uncover<2->{A \ar[r]}& B
}

\end{frame}

\end{document}
share|improve this question
2  
Not an answer, just pessimism: this sort of thing happens a lot with environments that nit-pick their contents. The AMS math environments also break \uncover, for example. This could be for any reason: for example, perhaps \ar[r] does not literally draw an arrow in place but sets a flag that xymatrix later interprets to place the arrow after drawing the entries of the matrix. In that case what you want is impossible. On the plus side, the analogous operation does work with TikZ. –  Ryan Reich Dec 29 '11 at 16:17
    
Also, based on the contents of the diagram you put in your last question, I think we know each other. Good to see you! –  Ryan Reich Dec 29 '11 at 16:20
2  
You can go with \only<1>{\xymatrix{{\phantom{A}}&B}}\only<2>{\xymatrix{A\ar[r]&B}}, but it's a horrible hack. You probably be better using TikZ. –  egreg Dec 29 '11 at 16:23
2  
For the record, I also recommend using TikZ. Its integration with beamer is remarkably good. It's almost as if they were written for each other. –  Loop Space Dec 29 '11 at 18:27
    
@RyanReich: Good to see you too! I updated my userinfo to eliminate any future guesswork;) –  David Zureick-Brown Dec 30 '11 at 17:11
add comment

3 Answers

up vote 5 down vote accepted

(I don't know anything about how xy parses its stuff so the xy bit is pure conjecture. However, I do know a bit about how beamer works its magic so that bit is less speculative.)

I think that Ryan's first comment is either true or close enough as to be a reasonable working assumption. This means that on the slide where you don't want the arrow to appear then you have to ensure that the \ar[r] code does not appear at all. The correct beamer code for this is the \only command as that throws away its argument without processing it (on the requisite slides).

However, you don't want the whole A \ar[r] thrown away because the A affects the spacing. You want the A to be there but just not shown. This is what \uncover does. It typesets its material, but using the background colour for the font so that it isn't shown. So you want \uncover for the A and \only for the \ar[r]. Thus:

\documentclass{beamer}
%\url{http://tex.stackexchange.com/q/39578/86}
\usepackage[all]{xy}    

\begin{document}

\begin{frame}[plain]

\xymatrix{
\uncover<2->{A} \only<2->{\ar[r]}& B
}

\end{frame}

\end{document}

I agree that it would be nice if this could be done automatically somehow, but I don't know enough (anything!) about the internals of xy so can't suggest how it might be done.

share|improve this answer
    
Awesome, thanks Andrew! –  David Zureick-Brown Dec 30 '11 at 17:15
add comment
\documentclass{beamer}
\usepackage[all]{xy}    
\begin{document}

\begin{frame}[plain]
\xymatrix{\onslide*<2->{A \ar[r]} & B}
\end{frame}

\end{document}
share|improve this answer
    
When I run that, the arrow shows up on both slides which isn't what the questioner wants (as I read it). Does the arrow appear on slide 1 for you? –  Loop Space Dec 29 '11 at 18:39
    
uups, you are right. change onslide+ to \onslide*, but then there is a little space –  Herbert Dec 29 '11 at 18:44
1  
That's because the first column goes from having width 0pt to having the width of the A. So the A needs to be there-but-hidden whilst the arrow needs to be not there at all. –  Loop Space Dec 29 '11 at 18:46
add comment

@Andrew: Your solution works very well, unless you have an arrow that also affects spacing. This happens for instance, if you have a curved arrow in your diagram.

So you also want \uncover for the arrow. Since that does not work, a very dirty workaround is to use \only to imitate the behaviour of \uncover: Write

\only<1>{\ar@[white][r]}
\only<2>{\ar[r]}

for the arrows. Assuming your background is white, this will typeset the arrow on slide 1 and make it invisible. On slide 2, you will see the arrow. You have to set the color option for the xy-package for this. If necessary, you can also use the color package to make labels invisible:

\only<1>{\ar@[white][r]^-{\color{white}f}}
\only<2>{\ar[r]^-{f}}

Doing it like that feels wrong, but it does the job. On all slides, the entire diagram has to be drawn in some color. Otherwise, it will wiggle around and your audience will get seasick.

share|improve this answer
add comment

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.