1

I have a tree drawn in tikz and want to animate its transformation to another tree. The structure of the trees is the same, it's just the labels (and for good measure the colours of the labels) which change. So, before: tree in tikz and after: another tree in tikz I want the animation to proceed row by row: first the bottom row changes, then the middle row, then the top rop.

How can I do this with least code duplication? I have seen a nice example showing how to change just the formatting on a frame-by-frame basis, but I want to change the labels as well as the formatting.

Code for the two trees follows.

\documentclass{beamer}
\usepackage{tikz}

\begin{document}

\begin{frame} \begin{tikzpicture} \node at (5cm, 0cm) {the} child {node at (-1.5cm, -.3cm) {quick} child {node at (-1cm, -.3cm) {brown}} child {node at (1cm, -.3cm) {fox}} } child {node at (1.7cm,-.3cm){jumped} child {node at (-.5cm, -.3cm) {over}} child {node at (.8cm, -.3cm) {the}} }; \end{tikzpicture}

\end{frame}

\begin{frame} \begin{tikzpicture} \node [red] at (5cm, 0cm) {now} child {node [red] at (-1.5cm, -.3cm) {is} child {node [red] at (-1cm, -.3cm) {the}} child {node [red] at (1cm, -.3cm) {time}} } child {node [red] at (1.7cm,-.3cm){for} child {node [red] at (-.5cm, -.3cm) {all}} child {node [red] at (.8cm, -.3cm) {good}} }; \end{tikzpicture}

\end{frame}

\end{document}

macbeth
  • 123

1 Answers1

3

You can use the \alt macro to exchange the text between overlays.

To avoid the tree from shifting between overlays, I suggest to combine this with a fixed width of the nodes and a \strut to give them all the same height:

\documentclass{beamer}
\usepackage{tikz}

\begin{document}

\begin{frame} \begin{tikzpicture}[every node/.style={text width=1.3cm,align=center}] \node at (5cm, 0cm) {\strut\alt<3->{\alert{now}}{the}} child {node at (-1.5cm, -.3cm) {quick} child {node at (-1cm, -.3cm) {brown}} child {node at (1cm, -.3cm) {fox}} } child {node at (1.7cm,-.3cm){jumped} child {node at (-.5cm, -.3cm) {over}} child {node at (.8cm, -.3cm) {the}} }; \end{tikzpicture}

\end{frame}

\end{document}

enter image description here