The title of this question might not be very accurate (I don't know for a better one so far), I am open to suggestion.

I have the nodes of a tree linked together with the command [edge from parent fork down]. But I want those edges be visible when I want. I can make disappear the vertices with the command visible on, as suggested in this post, but I cannot get rid of the edges.

If you run the code below, you will see what I mean. The first page is the complete tree. Then on page 2, what I want is to extract part of the tree for information purpose. So I removed the vertices, but as you can see, some edges are still there (the ones at the top of the tree), which is not what I want. I want only the desired part of the tree visible.
On pages 3 and 4, there are other examples to show the problem with the edges, while removing vertices.

So to be precise, I want the edges appearing not necessary at the same time as the vertices. I tried [edge from parent fork down, visible on = ] but all the tree disappears in that case.
Any suggestions?

Last question, more about curiosity. I used a lot of visible on as you can see, is there another way to do it without using so many times the same command?

\usetikzlibrary{trees, chains, positioning, through, arrows}


    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path

\newcommand\ppbb{path picture bounding box}


    node distance = 2mm and 2mm,
    start chain = going below,
    base/.style = {rectangle, draw, scale=0.6,
               inner sep=0mm,
               minimum height = 9mm, text width=25mm, align=center,
    T/.style = {path picture={\fill[blue!50!black]
                ([xshift=-4mm]\ppbb.north east) -| ([yshift=-4mm]\ppbb.north east) -- cycle;
                             }% end of path picture
boxB/.style = {base=####1, text width=20mm},
% on chain
 box/.style = {boxB=####1, on chain},
% tree's parameters
  level distance = 18mm,
sibling distance = 32mm,
  level 2/.style = {sibling distance = 25mm},
  level 3/.style = {sibling distance = 22mm}
% first part of image
% start of tree
\node[base=teal!50,visible on=<1>] {SCR}
    [edge from parent fork down]
    child { node[base=teal!30,visible on=<1>]      {Ajustement}}
    child { node[base=teal!30,visible on=<1>]    {BSCR}
        child { node[boxB=teal!10,visible on=<1>]    (Rba)   {Marché}}
        child { node[boxB=teal!10,visible on=<{1,2,4}>]    (Rbb)   {Santé}
            child { node[boxB=blue!20,visible on=<1-4>](Rca)   {SLT}}
            child { node[boxB=blue!20,visible on=<{1,2,4}>](Rcb)   {Catas\-trophe}}
            child { node[boxB=blue!20,visible on=<1-4>]  (Rcc)   {NSLT}}
        child { node[boxB=teal!10,visible on=<1>]    (Rbc)  {Contre-partie}}
        child { node[boxB=teal!10,visible on=<1>]    (Rbd)  {Vie}}
        child { node[boxB=teal!10,visible on=<1>]      (Rbe)  {Non-vie}}
        child { node[boxB=teal!10,visible on=<1>]      (Rbf)  {Actifs incorporels}}
    child { node[base=teal!10,visible on=<1>]  {Opérationnel}};
% Noeud Marché
{[start chain]
\coordinate[on chain,below=of Rba.west |- Rca.south]   (a);
\node[box=blue!20,visible on=<1>] (Rbaa) {Taux d'intérêt};
\node[box=blue!20,visible on=<1>] (Rbab) {Action};
\node[box=blue!20,visible on=<1>] (Rbac) {Immobilier};
\node[box=blue!20,visible on=<1>] (Rbad) {Spread};
\node[box=blue!20,visible on=<1>] (Rbae) {Change};
\node[box=blue!20,visible on=<1>] (Rbaf) {Concen\-tration};
\node[box=blue!20,visible on=<1>] (Rbag) {Illiquidité};
% Noeud Santé
{[start chain]
\coordinate[on chain,below=of Rcb.south west]   (b);
\node[box=blue!15,visible on=<1-3>] (Rbbaa)  {Mortalité};
\node[box=blue!15,visible on=<1-3>] (Rbbab)  {Longévité};
\node[box=blue!15,visible on=<1-3>] (Rbbac)  {Incapacité Invalidité};
\node[box=blue!15,visible on=<1-3>] (Rbbad)  {Rachat};
\node[box=blue!15,visible on=<1-3>] (Rbbae)  {Dépenses };
\node[box=blue!15,visible on=<1-3>] (Rbbaf)  {Révision};
% Noeud NSLT
{[start chain]
\coordinate[on chain,below=of Rcc.south east -| Rbc.east]   (c);
\node[box=blue!15,visible on=<1-3>] (Rbbca)  {Prime et réserve};
\node[box=blue!15,visible on=<1-3>] (Rbbcb)  {Rachat};
% Noeud Vie
{[start chain]
\coordinate[on chain,below left=of Rcc.south -| Rbe.west]    (d);
\node[box=blue!20,visible on=<1>] (Rbda) {Mortalité};
\node[box=blue!20,visible on=<1>] (Rbdb) {Longévité};
\node[box=blue!20,visible on=<1>] (Rbdc) {Incapacité Invalidité};
\node[box=blue!20,visible on=<1>] (Rbdd) {Rachat};
\node[box=blue!20,visible on=<1>] (Rbde) {Dépenses};
\node[box=blue!20,visible on=<1>] (Rbdf) {Révision};
\node[box=blue!20,visible on=<1>] (Rbdg) {Catas\-trophe};
% Noeud Non Vie
{[start chain]
\coordinate[on chain,below left=of Rcc.south -| Rbf.west]    (e);
\node[box=blue!20,visible on=<1>] (Rbea)   {Prime et réserve};
\node[box=blue!20,visible on=<1>] (Rbeb)   {Rachat};
\node[box=blue!20,visible on=<1>] (Rbec)   {Catas\-trophe};
% lines a
\coordinate[left=of Rbaa.west] (aa);
\visible<1>{\draw   (Rba) -- ++ (0,-0.9) -| (aa) -- (Rbaa);
\foreach \i [remember=\i as \ii (initially a)] in {b,c,...,g}
    \draw (aa |- Rba\ii) |- (Rba\i);}
% lines b
\visible<1-3>{\draw   (Rca) |- (Rbbaa);
\foreach \i [remember=\i as \ii (initially a)] in {b,c,...,f}
    \draw (Rca |- Rbba\ii) |- (Rbba\i);}
% lines d
\visible<1-3>{\draw   (Rcc) |- (Rbbca);
\draw   (Rcc) |- (Rbbcb);}
% lines e
\visible<1>{\draw   (Rbd) |- (Rbda);
\foreach \i [remember=\i as \ii (initially a)] in {b,c,...,g}
    \draw (Rbd |- Rbd\ii) |- (Rbd\i);}
% lines f
\visible<1>{\draw   (Rbe) |- (Rbea);
\foreach \i [remember=\i as \ii (initially a)] in {b,c}
    \draw (Rbe |- Rbe\ii) |- (Rbe\i);}

\node[boxB=teal!10] at (6,-13) {\rule[-0.05cm]{0cm}{0.45cm} module de risque};
\node[boxB=blue!20] at (9,-13) {\rule[-0.15cm]{0cm}{0.45cm} sous-module de risque};


  • 1
    Does it help? tex.stackexchange.com/a/167750/1952 – Ignasi Jun 14 '18 at 9:14
  • Forest would certainly allow you to specify the tree more compactly and to control visibility more automatically and/or flexibly. Would be good to know if that's an option. There are several posts with various examples combining forest with overlay specifications. – cfr Jun 15 '18 at 1:52
  • @Ignasi It does, even though you have to use forest instead of tree. Is there a way to do it with tree still? – Antoine Jun 16 '18 at 9:28
  • 1
    I get an error when I try to compile your code. ! Illegal parameter number in definition of \iterate. <to be read again> 1 l.155 \end{frame} ? Don't you? – cfr Jun 17 '18 at 1:00
  • 1
    If I fix the errors, I get a tree which is massively too large for the slide, so that most of it cannot be seen and it is really difficult to do anything with it. Moreover, the current overlay specifications give extremely odd results. What exactly are you trying to do? – cfr Jun 17 '18 at 23:15

You can control the visibility of sub trees by decoupling the tree from the parent, like discussed in How do I decouple child nodes in tikz trees into separate node elements?:

\node (r) {Root}
  child {coordinate (left)}
  child {coordinate {right)}
\node (c1) at (left) {Left Child};
\node (c2) at (right) {Right Child};

Then you can use \uncover on each individual \node ...; command.

However, for such a complex tree, the downside is, that you have to copy-paste each sub-tree in order for the size and automatic spacing to be computed correctly by tikz:

\node (r) {Root}
  child {node (left) {\phantom{Left Child}}}
  child {node (right) {\phantom{Right Child}}}
\node (c1) at (left) {Left Child};
\node (c2) at (right) {Right Child};

One could also make a script to generate this, I suppose.

| improve this answer | |
  • Thank you @bitmask It might work indeed, but as you said, it can be quite complicated to use in such a tree! – Antoine Aug 24 '18 at 15:03
  • I had good results in one case by drawing the entire tree invisibly once and then repeating each element ONCE as an independent \node by using the at syntax. – bitmask Aug 25 '18 at 10:04

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.