编辑

编辑

我正在尝试制作癌症治疗方案的决策树。以下是我目前所得到的: 在此处输入图片描述

我希望 NED 节点按下列方式进行更改:

  1. 我希望它位于页面的较高位置(或者,将“重复”节点位于页面的较低位置)

  2. 我希望 NED 节点的左边缘与 Recurrence 节点的左边缘对齐。

这是我希望树的开头看起来的样子的手绘图: 在此处输入图片描述

注意:我的代码基于这篇文章:封装森林:分叉边和分叉边的使用

这是我目前的代码:

\usepackage[edges]{forest}
\begin{document}


%adapted from: https://tex.stackexchange.com/questions/333595/package-forest-use-of-forked-edge-and-forked-edges
\begin{forest}
  forked edges,
  for tree={
    font=\small,
    draw,
    semithick,
    rounded corners,
    align = center,
    inner sep = 2mm,
    edge = {semithick, -stealth},
    grow = east,
    l sep = 19mm,
    fork sep=3mm,
  }
  [Active \\ Surveillance, fit = band
    [Recurrence
    [Other sites
        [Chemotherapy
            [PC-RPLND]
            [NED]
        ]
    ]
    [TM elevated
        [Chemotherapy
            [PC-RPLND]
            [NED]
        ]
        [RPLND
            [Chemotherapy]
            [NED]
        ]
    ]
    [Retroperitoneal recurrence \\ TM elevated,
        [RPLND
            [Chemotherapy]
            [NED]
            ]
        [Chemotherapy
            [PC-RPLND]
            [NED]
        ]
    ]
    [Retroperitoneal recurrence \\ TM normal
        [RPLND
            [Chemotherapy]
            [NED]
        ]
    ]   
     ]
    [NED, l =40mm]
  ]
\end{forest}

\end{document}

答案1

左对齐第三代和第四代子代

这是一个非常简单的修改Sašo 的回答,由于anchor已经是west,因此设置足以tier/.option=level确保给定代中的所有节点都按其左边缘对齐。

\documentclass{standalone}
\usepackage[edges]{forest}
\begin{document}
% ateb: https://tex.stackexchange.com/a/700208/
% addaswyd o ateb Sašo: https://tex.stackexchange.com/a/700185/
%adapted from: https://tex.stackexchange.com/questions/333595/package-forest-use-of-forked-edge-and-forked-edges
\begin{forest}
  forked edges,
  for tree={
    font=\small,
    draw,
    semithick,
    rounded corners,
    align = center,
    inner sep = 2mm,
    edge = {semithick, -stealth},
    grow = east,
    l sep = 19mm,
    fork sep=3mm,
    fit=band,
    anchor=west,
    tier/.option=level
  }
  [Active \\ Surveillance
    [Recurrence
    [Other sites
        [Chemotherapy
            [PC-RPLND]
            [NED]
        ]
    ]
    [TM elevated
        [Chemotherapy
            [PC-RPLND]
            [NED]
        ]
        [RPLND
            [Chemotherapy]
            [NED]
        ]
    ]
    [Retroperitoneal recurrence \\ TM elevated,
        [RPLND
            [Chemotherapy]
            [NED]
            ]
        [Chemotherapy
            [PC-RPLND]
            [NED]
        ]
    ]
    [Retroperitoneal recurrence \\ TM normal
        [RPLND
            [Chemotherapy]
            [NED]
        ]
    ]   
     ]
    [NED]
  ]
\end{forest}

\end{document}

编辑

forest[回复询问如何整合类似于手册第83-84 页中决策树所示的风格的评论。]

这里的情况稍微复杂一些,因为与示例决策树不同,我们有时会遇到 0、1、2 和 4 个子节点的情况。因此,我计算了子节点数量的一半加一,并edge根据子节点是否n小于结果(对于below)或不小于结果(对于above)将标签设置在 s 上方或下方。由于这些是概率,我假设只有一个子节点的情况可以忽略。(在这种情况下代码有效,但标签并不总是我可能喜欢放置的位置。)在其他树中,专门适应这种情况或使用完全不同的放置规则可能更有意义。

节点的内容和其标签的内容应以冒号分隔。我使用单个字母作为概率的占位符。例如,aardvark:animal将生成一个包含“土豚”的节点和一个edge label包含“动物”的节点。

\documentclass{standalone}
\usepackage[edges]{forest}
\begin{document}
% ateb: https://tex.stackexchange.com/a/700208/
% addaswyd o ateb Sašo: https://tex.stackexchange.com/a/700185/
%adapted from: https://tex.stackexchange.com/questions/333595/package-forest-use-of-forked-edge-and-forked-edges
\begin{forest}
  forked edges,
  for tree={
    font=\small,
    draw,
    semithick,
    rounded corners,
    align = center,
    inner sep = 2mm,
    edge = {semithick, -stealth},
    grow = east,
    l sep = 19mm,
    fork sep=3mm,
    fit=band,
    anchor=west,
    tier/.option=level
  },
  before typesetting nodes={%
    where n children=0{}{%
      tempcounta/.option=n children,
      tempcounta'+=1,
      for children={%
        split option={content}{:}{content,split edge label}, 
      },
    },
  },
  split edge label/.style={%
    if={>ORw+n<{n}{tempcounta}{##1/2}}{%
      edge label+={node [pos=0.75,below] {#1}}
    }{%
      edge label+={node [pos=0.75,above] {#1}}
    },
  }
  [Active \\ Surveillance
    [Recurrence:A
      [Other sites:a
          [Chemotherapy
              [PC-RPLND:c]
              [NED:d]
          ]
      ]
      [TM elevated:e
          [Chemotherapy:f
              [PC-RPLND:g]
              [NED:h]
          ]
          [RPLND:i
              [Chemotherapy:j]
              [NED:b]
          ]
      ]
      [Retroperitoneal recurrence \\ TM elevated:k,
          [RPLND:t
              [Chemotherapy:l]
              [NED:m]
              ]
          [Chemotherapy:s
              [PC-RPLND:n]
              [NED:o]
          ]
      ]
      [Retroperitoneal recurrence \\ TM normal:p
          [RPLND:q
              [Chemotherapy:v]
              [NED:r]
          ]
      ]   
    ]
    [NED:B]
  ]
\end{forest}

\end{document}

添加了边标签的树

答案2

fit=band是正确的想法,但它应该出现在NED节点上(其中l=40mm应该被删除的地方)。

或者(如下所示),fit=band可以将其应用于整个树,方法是将其包含在for tree

对于所需的对齐,包括anchor=west

\documentclass{standalone}
\usepackage[edges]{forest}
\begin{document}


%adapted from: https://tex.stackexchange.com/questions/333595/package-forest-use-of-forked-edge-and-forked-edges
\begin{forest}
  forked edges,
  for tree={
    font=\small,
    draw,
    semithick,
    rounded corners,
    align = center,
    inner sep = 2mm,
    edge = {semithick, -stealth},
    grow = east,
    l sep = 19mm,
    fork sep=3mm,
    fit=band,
    anchor=west,
  }
  [Active \\ Surveillance
    [Recurrence
    [Other sites
        [Chemotherapy
            [PC-RPLND]
            [NED]
        ]
    ]
    [TM elevated
        [Chemotherapy
            [PC-RPLND]
            [NED]
        ]
        [RPLND
            [Chemotherapy]
            [NED]
        ]
    ]
    [Retroperitoneal recurrence \\ TM elevated,
        [RPLND
            [Chemotherapy]
            [NED]
            ]
        [Chemotherapy
            [PC-RPLND]
            [NED]
        ]
    ]
    [Retroperitoneal recurrence \\ TM normal
        [RPLND
            [Chemotherapy]
            [NED]
        ]
    ]   
     ]
    [NED]
  ]
\end{forest}

\end{document}

结果树

相关内容