3

In the process of creating a family tree using forest, I have used forked edge style in the main for tree{}. However when the children node texts vary in length, the parent node's fork loses it's centering. I tried anchor=center, text centered, parent anchor=center and none produced the desired result.

Here is the MWE:

\begin{document}
    \begin{forest}
        % styles
        man/.style = {fill=green},
        woman/.style = {fill=yellow},
        for tree={draw={black, thick},
            edge = {draw, thick},
            rounded corners,
            inner sep=5pt,
            s sep=15mm,
            l sep=10mm,
            anchor=center,
            forked edge,
            text centered
        },
        % tree starts here
        [Parent, man
            [Child1, man
                [Child1, man]
                [Child345123231, man]
                [Chiild11, man]
                [Child5677, man]
                [Child123122, woman]
            ]
            [Child2, man
                [Child256677, man]
                [Child2412345, man]
                [Child2312, man]
            ]
            [Child3232, man
                [Child4343, man]
            ]
            [Child4223231131, woman]
        ]
    \end{forest}
\end{document}

And the result: enter image description here

Please help me avoid this by letting me know where I should add the necassary option. I'm sure this one has a simple solution (and many at that) but I'm not able to work it out.

4

You can use calign=child, calign child=[number] syntax to align the items.

MWE

\documentclass{standalone}
\usepackage[edges]{forest}
\begin{document}
    \begin{forest}
        % styles
        man/.style = {fill=green},
        woman/.style = {fill=yellow},
        for tree={draw={black, thick},
            edge = {draw, thick},
            rounded corners,
            inner sep=5pt,
            s sep=15mm,
            l sep=10mm,
            anchor=center,
            forked edge,
            text centered
        },
        % tree starts here
        [Parent, man
            [Child1, calign=child,calign child=3, man
                [Child1, man]
                [Child345123231, man]
                [Chiild11, man]
                [Child5677, man]
                [Child123122, woman]
            ]
            [Child2, calign=child,calign child=2, man
                [Child256677, man]
                [Child2412345, man]
                [Child2312, man]
            ]
            [Child3232, man
                [Child4343, man]
            ]
            [Child4223231131, woman]
        ]
    \end{forest} 
\end{document}

enter image description here

1
  • Thanks a lot! Now even the docs make sense. – Veera Raagavan Jun 23 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.