2

I am trying to make a decision tree for cancer treatment options. Here is what I have so far: enter image description here

I would like the NED node to be changed in the following ways:

  1. I would like it to be positioned higher up on the page (or, equivalently, to have the Recurrence node positioned lower down on the page)

  2. I would like the the left edge of the NED node to be aligned with the left edge of the Recurrence node.

Here is a hand drawing of what I would like the start of the tree to look like: enter image description here

Note: I have based my code from this post: Package forest: use of forked edge and forked edges

Here is my code so far:

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

2 Answers 2

3

left aligning third and fourth generation children

This is a very simple modification of Sašo's answer, Since anchor is already west, it is sufficient to set tier/.option=level to ensure all nodes in a given generation are aligned by their left edges.

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

Edit

[In response to comment asking how to integrate a style like that shown for the decision tree on pages 83-84 of forest's manual.]

The case here is a little more complicated because, unlike the example decision tree, we sometimes have cases of 0, 1, 2 and 4 children. I've therefore calculated half the number of children plus one and set the labels above or below the edges according to whether the child's n is less than the result (for below) or not (for above). Since these are probabilities, I assume the case where there is only a single child can be ignored. (The code works in that case, but the label isn't always where I might prefer to put it.) In other trees, it might make sense to accommodate this case specifically or to use a different rule for placement altogether.

The node's content and its label's content should be separated by a colon. I've used single letters as placeholders for probabilities. For example, aardvark:animal would produce a node containing 'aardvark' and an edge label containing 'animal'.

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

tree with added edge labels

6
  • Yes, this is perfect! Thank you. One other question: How would I place a small piece of text to indicate the probabilities? I tried reading the forest manual, and found something that looked like what I want on page 83 (mirror.mwt.me/ctan/graphics/pgf/contrib/forest/forest-doc.pdf). However, I was not able to duplicate that code in my example.
    – Sam
    Nov 2, 2023 at 14:12
  • @Sam Do you mean the decision tree which splits the content of the nodes to create labels midway along the edges? (The picture at the bottom of 83 with N as the root node?
    – cfr
    Nov 2, 2023 at 14:41
  • Yes, that is exactly what I am referring to!
    – Sam
    Nov 2, 2023 at 14:49
  • @Sam See edit above.
    – cfr
    Nov 2, 2023 at 16:46
  • 1
    This is perfect, thank you! I want to try and study your code and see if I can understand it, so that I can make any modifications on my own without bothering you :) If I have more questions after reading your code, I will leave a comment.
    – Sam
    Nov 3, 2023 at 18:06
4

fit=band is the right idea, but it should appear on the NED node (where l=40mm should be removed).

Alternatively (and as shown below), fit=band can be applied to the entire tree, by including it among keys in for tree.

For the desired alignment, include 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}

resulting tree

2
  • This is helpful, but the 3rd generation children and the 4th generation children are not left aligned. Do you know how to fix this? (I can include a picture in my original question if this would be useful.)
    – Sam
    Nov 1, 2023 at 23:59
  • @Sam See below. Is that what you mean by 'left aligned'?
    – cfr
    Nov 2, 2023 at 2:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .