5

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 ] ] ]}

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

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

3

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.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{tikz-qtree}
\tikzset{edge from parent/.style={draw,very thick}}
\begin{document}
\begin{frame}[t]
    \frametitle{A tree}
    \begin{tikzpicture}
    \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 ]]}
    \end{tikzpicture}
\end{frame}

\end{document}

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.

2
\documentclass{beamer}
\usepackage{qtree}
\begin{document}
\begin{frame}[t]{A tree}

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

\end{frame}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy