如何固定森林树木的分叉

如何固定森林树木的分叉

在使用森林创建家谱的过程中,我forked edge主要使用了风格for tree{}。然而当子节点文本长度不同时,父节点的分叉将失去其居中。我尝试了anchor=center,,text centeredparent anchor=center都没有产生预期的结果。

以下是 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}

结果如下: 在此处输入图片描述

请帮助我避免这种情况,让我知道我应该在哪里添加必要的选项。我确信这个问题有一个简单的解决方案(而且有很多),但我无法解决。

答案1

您可以使用calign=child, calign child=[number]语法来对齐项目。

平均能量损失

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

在此处输入图片描述

相关内容