9

Imagine a simple tree:

\begin{tikzpicture}
    \node {Selbstregulation}
    [edge from parent fork down]
    child {node {Kognition}}
    child {node {Metakognition}
      child {node {Planung}}
      child {node {Monotoring}}
      child {node {Regulation}}
    }
\end{tikzpicture}

Is it possible to unveil the child nodes step by step using overlays in beamer? I tried with the \onslide command at several positions around child, but it doesn't work...

Any hints? - Thanks.

10

A TikZ option to set the color to white depending on the current slide:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{trees}

\tikzset{hide on/.code={\only<#1>{\color{white}}}}

\begin{document}
\begin{frame}  
\begin{tikzpicture}
   \only<4>{} % Force beamer to show the correct amount of slides
    \node {Selbstregulation}
    [edge from parent fork down]
    child {node {Kognition}}
    child {node  {Metakognition}
      child [hide on=-2]  {node {Planung}}
      child [hide on=-3] {node {Monotoring}}
      child [hide on=1] {node {Regulation}}
    };
\end{tikzpicture}
\end{frame}
\end{document}

Placing the [hide on=..] option to get the right effect is a bit tricky. For example, the downward line is always drawn with the last child, so that node has to be uncovered first.

(Also note that the \tikzset has to be called outside the frames (I guess for reasons of catcode trickery).)

  • 2
    Maybe it’s better to change the opacity to 0 instead of setting the color to withe, because the latter will keep visible on backgrounds with different colors (e.g. gradients or images). I didn’t test it so I’m not sure if it works … – Tobi Mar 4 '12 at 13:01
4

I have been told this is not possible. The package author wrote in 2005 that it wasn't. If the ability has been added I do not know of it.

My correspondent's advice is the best workaround that I can think of:

To get the same effect, you may want to try drawing the final figure and then work backwards, making this invisible by making them have the same color as the background or transparent.

  • Thanks. To get it clear: you are suggesting that I should create the whole tree and copy-paste the picture on the preceding frames making the corresponding transparency changes? The problem here is that the connection lines beween the nodes remain visible, if set a node to be transparent... – Fred Jun 13 '11 at 12:01
  • @Fred: To hide individual nodes, you can use {\only<2->{Planung}} for the node text. – Caramdir Jun 13 '11 at 16:36
1

I improved the answer of Caramdir using opacity instead of color white, changing:

\tikzset{hide on/.code={\only<#1>{\color{white}}}}

with:

\tikzset{hide on/.code={\only<#1>{\color{fg!20}}}}

in my case I wanted a semitransparent effect, you can also set "fg!0" for full hiding, or any other level of opacity.

the full code is:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{trees}

\tikzset{hide on/.code={\only<#1>{\color{fg!20}}}}

\begin{document}
\begin{frame}  
\begin{tikzpicture}
   \only<4>{} % Force beamer to show the correct amount of slides
    \node {Selbstregulation}
    [edge from parent fork down]
    child {node {Kognition}}
    child {node  {Metakognition}
      child [hide on=-2]  {node {Planung}}
      child [hide on=-3] {node {Monotoring}}
      child [hide on=1] {node {Regulation}}
    };
\end{tikzpicture}
\end{frame}
\end{document}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.