4

I want to display a tikz tree node by node. First A, then A and B and in the end all nodes. Note that I need to do it with the presented format:

\Tree
[. \node{A};]

since trees are automatically generated in this format and I want to only modify them not to destroy. I tried putting a subtree in \visible<>{} but no success. If I use [opacity=0] for a node then arcs are still visible. How to make a subtree invisible? that's would really solve my problem.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{tikz-qtree-compat}

\begin{document}

\begin{frame}
\only<4>{}
%\setbeamercovered{invisible}
\begin{tikzpicture}[grow=down]
    \tikzset{level distance = 25pt, sibling distance = 10pt}
    \tikzset{every tree node/.style={align=center,anchor=north}}
    \Tree
      [. \node{A};
        [. \node{B};
          [. \node{C};]
        ]
      ]     
\end{tikzpicture}
\end{frame}
\end{document}
1
  • Too bad you are not using forest! I also have code to do this in qtree but both of those packages use the standard bracket notation which you are not using. (That is, you have [. \node{A};] rather than [{A}] or [.{A}].
    – cfr
    Nov 22, 2014 at 16:23

1 Answer 1

4

One option using the visible on style and \edge operation to have control over the edges, allowing to stepwise reveal them:

enter image description here

The code:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{tikz-qtree-compat}

\tikzset{
  invisible/.style={opacity=0},
  alt/.code args={<#1>#2#3}{%
    \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} 
  },
  visible on/.style={alt=#1{}{invisible}},
}

\begin{document}

\begin{frame}

\begin{tikzpicture}[grow=down]
    \tikzset{level distance = 25pt, sibling distance = 10pt}
    \tikzset{every tree node/.style={align=center,anchor=north}}
    \Tree
      [. \node[visible on=<1->]{A};\edge[visible on=<2->];
        [. \node[visible on=<2->]{B};\edge[visible on=<3->];
          [. \node[visible on=<3>]{C};]
        ]
      ]     
\end{tikzpicture}
\end{frame}
\end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .