如何修改森林树?

如何修改森林树?

%我需要获取两个上层之间共享的最后一层。我该如何编写代码?

\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}  

答案1

小孩phantom可以帮助将节点置于中心。

\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}  

在此处输入图片描述

答案2

到目前为止我已经完成了这个(见下文),但我没能将最后一个级别居中:

\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} 

在此处输入图片描述

相关内容