2

Suppose I have the following tree:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[edges]{forest}

\begin{document}

\begin{forest}
    for tree={
      grow=east,
      parent anchor=east,
      child anchor=west,
      align=center,
      l=1em,anchor=base west,
       edge path={
                \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(5pt,0) |- (.child anchor)\forestoption{edge label};
            },
      for root={
        parent anchor=east,
      },
    }
    [Main Branch,rotate=90,child anchor=north, parent anchor=south, anchor=center
      [Hello1
            [Hello2
                ]
            [Hello3
                ]
      ]
      [Hello4
          [Hello5]
          [Hello6]
          [Hello7]
          [Hello8]
          [Hello9]
     ]
    ]
\end{forest}


\end{document}

This gives the following output:

Forest1

I want to make two changes:

  1. Increase the line of the Main Branch, like this:

forest2

  1. Ensure that the line on the east side (highlighted in red in the figure below) of each label has exactly the same length as on the west side. So in this case, I want to increase it a little bit.

forest3

I have tried to change the length of the labels (l) but that did not produce the desired results.

1 Answer 1

2

You don't have to define that kind of edge—the style forked edge is built in to the edges library. You can place forked edges outside the for tree to do the whole tree, or individual edges with forked edge. Then the option fork sep is available. Since the total distance is 4mm, set the fork sep to 2mm to get the split halfway.

The extra length from the root can be accomplished by increasing fork sep for the children and increasing l sep for the root.

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[edges]{forest}

\begin{document}

\begin{forest}
forked edges,
    for tree={fork sep=2mm,
      grow=east,
      parent anchor=east,
      child anchor=west,
      align=center,
      anchor=base west,
      l sep=4mm
    }
    [Main Branch, rotate=90, child anchor=north, parent anchor=south, anchor=center, l sep+=2mm, for children={fork sep+=2mm}
        [Hello1
            [Hello2]
            [Hello3]
        ]
        [Hello4
            [Hello5]
            [Hello6]
            [Hello7]
            [Hello8]
            [Hello9]
        ]
    ]
\end{forest}

\end{document}
4
  • Perfect! Thanks a lot. Now, with the forked edges style, how can I change the length of the lines between the child node (on the west side) and the parent? The problem is that I might also have the following children: [,coordinate,l=1cm, [Hello10] [Hello11] ] and then with the forked edges option the line is significantly longer than that of the other children.
    – John Doe
    Commented Jun 13 at 20:08
  • @JohnDoe: You should probably post a new question and include a link to this one.
    – Sandy G
    Commented Jun 13 at 21:03
  • @JohnDoe You shouldn't be loading inputenc with any non-ancient version of LaTeX. If you do ask a new question, please explain what you want to happen. Why insert the coordinate at all? Is that the child of another node and the point is just to get the fork?
    – cfr
    Commented Jun 13 at 23:33
  • @cfr Thanks a lot! I have opened a new question: tex.stackexchange.com/q/720575/313365
    – John Doe
    Commented Jun 14 at 15:31

You must log in to answer this question.

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