Take the 2-minute tour ×

I'm trying to do a beamer animation of a parse of a simple binary branching tree. I'd like to either use different colored branches and node labels to code the different steps of the parser and/or animate the parse. I don't know how to use \pause in the middle of a tree. Is that possible?

If I try to just do separate frames for each stage of the tree, LaTeX automatically resizes everything, so one node takes up a huge space on slide one, but less on slide two when it's joined with its daughters ... so it looks weird. Not like a structure that's being built one step at a time.

Any suggestions would be much appreciated!

{\Tree [.1 [.2 a ] [.3 [.4 b ] [.5 c ] ] ]}
share|improve this question

migrated from stackoverflow.com Mar 13 '12 at 7:11

This question came from our site for professional and enthusiast programmers.

This is very difficult to do; and it may not be possible at all with tikz-qtree. See Beamer & TikZ: gradually unveil trees which is related, although not an exact duplicate, since it doesn't refer to qtree. –  Alan Munn Mar 13 '12 at 13:53
You might be able to apply the same technique as in the question I linked to in tikz-qtree. See How to specify left and right node of a tikz-qtree and How do I make an unbalanced binary tree for tips on how to add styles to particular edges or nodes in a tikz-qtree. –  Alan Munn Mar 13 '12 at 14:03

2 Answers 2

For a simple animation that, e.g. presents distinct levels of the tree one at a time, you can just use \only<> and successively larger trees. If you use the [t] alignment option on the frame, you don't get the spacing problem you refer to.

\tikzset{edge from parent/.style={draw,very thick}}
    \frametitle{A tree}
    \only<1>{\Tree [.A B C ]}
    \only<2>{\Tree [.A [.B D E ] [.C ]]}
    \only<3>{\Tree [.A [.B D E ] [.C F G ]]}
    \only<4>{\Tree [.A [.B \edge[red]; \node{D}; \edge[blue]; \node{E}; ] [.C [.F H I ] G ]]}


Colouring branches is fairly easy (I've given one example in the last version of the tree); using the same technique to animate everything isn't very easy, however.

share|improve this answer
\begin{frame}[t]{A tree}

\Tree [.1 [ .2 \pause a ] [.3 [.4 \pause b ] [.5 \pause c ] ] ]

share|improve this answer

Your Answer

