4

Consider the following forest:

\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]
            [VeryVeryVeryLongHello6]
            [Hello7,
                [,coordinate,l=4.5cm,yshift=0.76mm,
                        [NormalHello1]
                        [NormalHello2]
                ]
            ]
            [VeryVeryVeryLongHello8]
            [Hello9]
        ]
    ]
\end{forest}


\end{document}

This produces the following figure:

Forest

What I don't like about this tree is that the lines of NormalHello2 and NormalHello1 on the west side are too long when compared to the rest of the children in the tree.

The end result should look something like this:

forest2

0

1 Answer 1

4

Increase l sep for the parent node and increase fork sep for the children by the same amount. You don't need the extra coordinate node.

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]
            [VeryVeryVeryLongHello6]
            [Hello7, l sep+=3.2cm, for children={fork sep+=3.2cm}
                        [NormalHello1]
                        [NormalHello2]
            ]
            [VeryVeryVeryLongHello8]
            [Hello9]
        ]
    ]
\end{forest}
\end{document}
2
  • 1
    Amazing. Thank you so much!
    – John Doe
    Commented Jun 14 at 17:59
  • @JohnDoe You can make the code a bit faster if you use ' when changing e.g. dimensions etc. if they are provided by forest rather than tikz.
    – cfr
    Commented Jun 14 at 18:14

You must log in to answer this question.

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