12

How can I uncover the nodes in the following tikzpicture? I want to display all red nodes, followed by all green nodes, and then followed by all blue nodes.

\tikzstyle{level 1}=[sibling angle=120]
\tikzstyle{level 2}=[sibling angle=60]
\tikzstyle{level 3}=[sibling angle=30]
\tikzstyle{every node}=[fill,inner sep=0pt,minimum size=4pt]
\tikzstyle{edge from parent}=[segment length=1mm,
                          segment angle=10,draw] 
\begin{tikzpicture}[grow cyclic,shape=circle,very thick,level distance=13mm,
                cap=round,scale=0.5]
\node {} child [color=\A] foreach \A in {red,red,red}
{  node {} child [color=\A!50!\B] foreach \B in {green,green,green}
     { node {} child [color=\A!50!\B!50!\C] foreach \C in {blue,blue,blue}
         { node {} }
    }
};
\end{tikzpicture}
  • 1
    While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill May 20 '12 at 7:22
  • 2
    Note that \tikzstyle is deprecated. See e.g. Should \tikzset or \tikzstyle be used to define TikZ styles? – Martin Scharrer May 20 '12 at 9:53
  • @PeterGrill: Thanks for the note. I would provide MWE for my questions. – Sandeep May 21 '12 at 0:56
20

In this solution I applied the Daniel's method shown in Mindmap tikzpicture in beamer (reveal step by step): it has several advantages and it is very simple to be used.

In the following code, with respect to the MWE provided, I shifted in the preamble the style definitions:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{trees,decorations}
\usetheme{EastLansing}

% style definitions
\tikzset{level 1/.style={sibling angle=120}}
\tikzset{level 2/.style={sibling angle=60}}
\tikzset{level 3/.style={sibling angle=30}}
\tikzset{every node/.style={fill,inner sep=0pt,minimum size=4pt}}
\tikzset{edge from parent/.style={segment length=1mm,
                          segment angle=10,draw}}

% Daniel's code:
% https://tex.stackexchange.com/questions/55806/tikzpicture-in-beamer/55827#55827
  \tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
  }


\begin{document}
\begin{frame}{Title}
\begin{center}
\begin{tikzpicture}[grow cyclic,shape=circle,very thick,level distance=13mm,
                cap=round,scale=0.5]
\node {} child [color=\A,visible on=<1->] foreach \A in {red,red,red}
{  node {} child [color=\A!50!\B,visible on=<2->] foreach \B in {green,green,green}
     { node {} child [color=\A!50!\B!50!\C,visible on=<3->] foreach \C in {blue,blue,blue}
         { node {} }
    }
};
\end{tikzpicture}
\end{center}
\end{frame}

\end{document}

What you simply have to do, once inserted in the preamble the Daniel's code, is to define in which time instant you want to display nodes; the method is to add in child options visible on=<...>.

Finally, what you get are those three frames:

enter image description here

  • 1
    A really cool feature of this approach is that you can even use visible on=<\slide-> in a \foreach \slide in {...} loop. This is also not possible with the standard TikZ syntax. – cgogolin Mar 8 '16 at 17:03

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.