1

%I need to get the very last level shared between the two upper levels. How can I code that?

\documentclass[tikz,border=10pt]{standalone}  
\usepackage{forest}  
\usetikzlibrary{shadows}  
\begin{document}  
\begin{forest}  
  shade me/.style={%  
    bottom color=#1!25,  
    top color=#1!5,  
    draw=#1,  
    drop shadow,  
    font=\large,  
  },  
  my label/.style n args=2{%  
    edge label={node [midway, black, font=\sffamily\large, #1] {#2}}  
  },  
  where n children=0{%  
    shade me=blue!50!cyan,  
  }{%  
    if level=0{%  
      shade me=green!75!gray,  
    }{%  
      shade me=blue!75!magenta,  
    }  
  },  
  for tree={%  
    delay={content/.wrap value={\strut #1}},  
    edge={red,->},  
    l sep+=25pt,  
    s sep+=20pt  
  }  
  [100000 individuals  
  [100 affected, my label={above, xshift=1cm}{}  
      %[No, my label={above, sloped}{$< 30$}]  
      [{95\% true positives}, my label={below, xshift=-1.7cm}{}  
    [{95 + 999 test positive Total = 1094}, my label={above, sloped}{}]]]  
    [99900 unaffected, my label={above, sloped}{}  
      [{1\% false positives}, my label={below, xshift=1.5cm}{}  
  [{95 + 999 test positive Total = 1094}, my label={above, sloped}{}]]]        ]  
    ]  
  ]  
\end{forest}  
\end{document}  
  • I need to get the very last level (95 + 999 test positive Total = 1094) becoming shared between the two boxes above it. How can I code that? – Reza Jun 7 '16 at 16:48
  • If you based your code on somebody else's, don't forget that you should attribute it. This is a matter of courtesy, but it also helps people follow-up by directing them to closely related questions via links, which can be enormously helpful. – cfr Jun 7 '16 at 22:01
5

A phantom child can help to center the node.

\documentclass[tikz,border=10pt]{standalone}  
\usepackage{forest}  
\usetikzlibrary{shadows}  
\begin{document}  
\begin{forest}  
  shade me/.style={%  
    bottom color=#1!25,  
    top color=#1!5,  
    draw=#1,  
    drop shadow,  
    font=\large,  
  },  
  my label/.style n args=2{%  
    edge label={node [midway, black, font=\sffamily\large, #1] {#2}}  
  },  
  where n children=0{%  
    shade me=blue!50!cyan,  
  }{%  
    if level=0{%  
      shade me=green!75!gray,  
    }{%  
      shade me=blue!75!magenta,  
    }  
  },  
  for tree={%  
    delay={content/.wrap value={\strut #1}},  
    edge={red,->},  
    l sep+=25pt,  
    s sep+=20pt  
  }  
  [100000 individuals  
  [100 affected, my label={above, xshift=1cm}{}  
      %[No, my label={above, sloped}{$< 30$}]  
      [{95\% true positives}, my label={below, xshift=-1.7cm}{}  
    [,phantom] [{95 + 999 test positive Total = 1094}, my label={above, sloped}{}, name=aux1]]]  
    [99900 unaffected, my label={above, sloped}{}  
      [{1\% false positives}, my label={below, xshift=1.5cm}{}, name=aux  
 % [{95 + 999 test positive Total = 1094}, my label={above, sloped}{}]
 ]]        ]  
    ]  
  ]  
  \draw[red, ->] (aux)--(aux1);
\end{forest}  
\end{document}  

enter image description here

3

So far I have done this (see below) but I didn't manage to center the last level :

\documentclass[tikz,border=10pt]{standalone}  
\usepackage{forest}  
\usetikzlibrary{shadows, positioning}
\begin{document}  
\begin{forest}  
  shade me/.style={%  
    bottom color=#1!25,  
    top color=#1!5,  
    draw=#1,  
    drop shadow,  
    font=\large,  
  },  
  my label/.style n args=2{%  
    edge label={node [midway, black, font=\sffamily\large, #1] {#2}}  
  },  
  where n children=0{%  
    shade me=blue!50!cyan,  
  }{%  
    if level=0{%  
      shade me=green!75!gray,  
    }{%  
      shade me=blue!75!magenta,  
    }  
  },  
  for tree={%  
    delay={content/.wrap value={\strut #1}},  
    edge={red,->},  
    l sep+=25pt,  
    s sep+=20pt  
  }  
  [100000 individuals, name=init,
  [100 affected, my label={above, xshift=1cm}{}  
  % [No, my label={above, sloped}{$< 30$}]  
  [{95\% true positives}, my label={below, xshift=-1.7cm}{}  
  [{95 + 999 test positive Total = 1094}, name=end, below=(1cm of init), my label={above, sloped}{}]]]
  [99900 unaffected, my label={above, sloped}{}  
  [{1\% false positives}, name=start,my label={below, xshift=1.5cm}{} 
  % [{95 + 999 test positive Total = 1094}, my label={above, sloped}{}]]]
  ]  
  ]
  ]
  \draw[->, red](start) -- (end);
\end{forest}  
\end{document} 

enter image description here

  • Thanks a lot. That's great you made great modifications. I don't know how to centralize the last line @flav – Reza Jun 7 '16 at 17:28

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.