森林中零星节点重叠

森林中零星节点重叠

有一个节点,其子节点与下面的 MWE 中邻居节点的子节点边重叠(节点 10070070 和 10071027 的子节点,文本为 ZZZZ 和 YYYY)。

节点 Y 似乎被稍微向左推向节点 Z。

节点 Z 似乎被推得比其应有的位置略低。

在此处输入图片描述

节点 Z 和其余节点之间的唯一区别似乎是其第二行文本中间有一个新行,因此它有 4 行,而其余的只有 3 行。新行是不可避免的,因为整个 Forest 都是由机器从分层数据库中生成的,并且某些字符串必须有换行符,这是一条业务规则。我认为这minimum height=10ex应该已经解决了这个问题。

有没有什么方法可以确保无论 Forest 节点内有多少行文本,只要文本不会使节点垂直扩展,它就会与其余部分统一渲染?

\documentclass[border=10pt]{standalone}
\usepackage{forest}

\begin{document}

\begin{forest} 
for tree={
    draw=black, align=center, l sep=4ex, parent anchor=south, child anchor=north,
    node options={font=\scriptsize, minimum width=14em, minimum height=10ex, rounded corners=1ex},
    edge path={
        \noexpand\path[\forestoption{edge}]
        (!u.parent anchor) -- +(0,-2ex) -| (.child anchor)\forestoption{edge label};
    },
    where n children=0{
        child anchor=west,
        edge path={
            \noexpand\path[\forestoption{edge}]
            ([xshift=-6em]!u.parent anchor) |- (.child anchor)\forestoption{edge label};
        },
        draw=red,for parent={
            parent anchor=south, l sep=-12em, grow'=east, calign=child edge, draw=blue          
        }
    }{}
}
[\textbf{AAAAAAAA AAAAAAAAAAA}\\AAAAAAAAA AAAA AAAAAAAAA\\AAAAAAAAAAA ,name=10005246
    [\textbf{AAAAA AAAAAAA}\\AAAAA AAAAAAA\\AAAAAAA ,name=10070085
        [\textbf{AAAAAAAA AAAAAAAA}\\AAAAAAAAA AAAAAAA\\AAAAAAA ,name=10070058
            [,phantom, minimum height=0ex]
            [\textbf{AAAAA AAAAAAAAA}\\AAAAAAAAA AAAAAAAAAAA\\AAAAAAA ,name=10071084]
        ]
        [\textbf{AAA AAAAAAA}\\AAAAAAAAAAAAA AAAA AAAAAAA\\AAAAAAA ,name=10070066
            [,phantom, minimum height=0ex]
            [\textbf{AAAA AAAAA}\\AAAAAAA AAAAAAAA\\AAAAAAA ,name=10070063]
            [\textbf{AAAA AAAAAA}\\AAAAA AAAAAAAA\\AAAAAAA ,name=10070107]
            [\textbf{AAAAAAA AAA}\\AAAAA AAAAAAAA\\AAAAAAA ,name=10070109]
            [\textbf{AAAA AAAAAAAA}\\AAAAAAA AAAAAAAA\\AAAAAAA ,name=10070119]
            [\textbf{AAAA AAAAA}\\AAAAA AAAAAAAA\\AAAAAAA ,name=10070122]
        ]
        [\textbf{AAAAAA AAAAAAA}\\AA AAAAAAA AAAAAAA\\AAAAAAA ,name=10070076
            [,phantom, minimum height=0ex]
            [\textbf{AAAAAAA AAAAAA}\\AAAAAAA AAAAAAAAAA\\AAAAAAA ,name=10070116]
            [\textbf{AAAAA AAAAAA}\\AAAAAAA AAAAAAAAAA\\AAAAAAA ,name=10070118]
        ]
        [\textbf{AAAAAA AAAAAAA}\\AAAAAAAAAA AAAAAAA\\AAAAAAA ,name=10070081
            [\textbf{ZZZZZ ZZZZZZ}\\ZZZZZZZ\\ZZZZZZZ ZZZZZZZ\\ZZZZZZZ ,name=10070070
                [,phantom, minimum height=0ex]
                [\textbf{ZZZZZZZ ZZZZZ}\\ZZZZ ZZZZZZZZ\\ZZZZZZZ ,name=10070117]
                [\textbf{ZZZZZZZ ZZZZZ}\\ZZZZ ZZZZZZZZ\\ZZZZZZZ ,name=10070121]
                [\textbf{AAAAA AAAAAA}\\AAAA AAAAAAAA\\AAAAAAA ,name=10071097]
            ]
            % The children of the node below overlaps the children of the node above
            [\textbf{YYYYYY YYYYYYYY}\\YYYYYYYYYY YYYYYYY\\YYYYYYY ,name=10071027
                [,phantom, minimum height=0ex]
                [\textbf{YYYYY YYYYYYYY}\\YYYYYYYYYY YYYYYYYYYY\\YYYYYYY ,name=10070089]
                [\textbf{YYYYYYY Y YYYYYY}\\YYYYYYYYYY YYYYYYYYYY\\YYYYYYY ,name=10071317]
            ]
            [\textbf{AAAAAA AAAAAAAAAAAAAA}\\AAAAAAAAAA AAAAAAAAAA\\AAAAAAA ,name=10070059
                [,phantom]
            ]
            [\textbf{AAAA AAAAA}\\AAAA AAAAAAAA\\AAAAAAA ,name=10070061
                [,phantom]
            ]
            [\textbf{AAAAAAA AAAAAAAA}\\AAAA AAAAAAAA\\AAAAAAA ,name=10070078
                [,phantom]
            ]
            [\textbf{AAAAAAA AAAAAAAAA}\\AAAA AAAAAAAA\\AAAAAAA ,name=10070091
                [,phantom]
            ]
            [\textbf{AAAAAAA AAAAAA }\\AAAAAAAAAA AAAAAAAAAA\\AAAAAAA ,name=10070120
                [,phantom]
            ]
        ]
        [\textbf{AAAAAAA AAAAAAAAA}\\AA AAAAAAA\\AAAAAAA ,name=10070098
            [,phantom, minimum height=0ex]
            [\textbf{AAAA AAAA}\\AAAAAAA\\AAAA AAAAAAAAAA\\AAAAAAA ,name=10070105]
            [\textbf{AAAAA AAAAAAAA}\\AA AAAAA\\AAAAAAA ,name=10070111]
            [\textbf{AAAAAAA AAAAAAAA}\\AA AAAAAAAAAA\\AAAAAAA ,name=10070115]
        ]
        [\textbf{AAAA AAAAAAAAA}\\AAAAAAAA AAAA AAAAAAAAAA\\AAAAAAA ,name=10011825
            [,phantom]
        ]
        [\textbf{AAAAAAAA AAAAA}\\AAAAAAAAAA{,} AAA\\AAAAAAA,name=10070079
            [,phantom]
        ]
    ]
]
\end{forest}
\end{document}

答案1

添加base=b以使节点的表格内容与基线对齐而不是顶部:

\documentclass[border=10pt]{standalone}
\usepackage{forest}

\begin{document}

  \begin{forest}
    for tree={
      draw=black, align=center, l sep=4ex, parent anchor=south, child anchor=north,
      node options={font=\scriptsize, minimum width=14em, minimum height=10ex, rounded corners=1ex},
      edge path={
        \noexpand\path[\forestoption{edge}]
        (!u.parent anchor) -- +(0,-2ex) -| (.child anchor)\forestoption{edge label};
      },
      where n children=0{
        child anchor=west,
        edge path={
          \noexpand\path[\forestoption{edge}]
          ([xshift=-6em]!u.parent anchor) |- (.child anchor)\forestoption{edge label};
        },
        draw=red,for parent={
          parent anchor=south, l sep=-12em, grow'=east, calign=child edge, draw=blue
        }
      }{},
      base=b
    }
    [\textbf{AAAAAAAA AAAAAAAAAAA}\\AAAAAAAAA AAAA AAAAAAAAA\\AAAAAAAAAAA ,name=10005246
    [\textbf{AAAAA AAAAAAA}\\AAAAA AAAAAAA\\AAAAAAA ,name=10070085
    [\textbf{AAAAAAAA AAAAAAAA}\\AAAAAAAAA AAAAAAA\\AAAAAAA ,name=10070058
    [,phantom, minimum height=0ex]
    [\textbf{AAAAA AAAAAAAAA}\\AAAAAAAAA AAAAAAAAAAA\\AAAAAAA ,name=10071084]
    ]
    [\textbf{AAA AAAAAAA}\\AAAAAAAAAAAAA AAAA AAAAAAA\\AAAAAAA ,name=10070066
    [,phantom, minimum height=0ex]
    [\textbf{AAAA AAAAA}\\AAAAAAA AAAAAAAA\\AAAAAAA ,name=10070063]
    [\textbf{AAAA AAAAAA}\\AAAAA AAAAAAAA\\AAAAAAA ,name=10070107]
    [\textbf{AAAAAAA AAA}\\AAAAA AAAAAAAA\\AAAAAAA ,name=10070109]
    [\textbf{AAAA AAAAAAAA}\\AAAAAAA AAAAAAAA\\AAAAAAA ,name=10070119]
    [\textbf{AAAA AAAAA}\\AAAAA AAAAAAAA\\AAAAAAA ,name=10070122]
    ]
    [\textbf{AAAAAA AAAAAAA}\\AA AAAAAAA AAAAAAA\\AAAAAAA ,name=10070076
    [,phantom, minimum height=0ex]
    [\textbf{AAAAAAA AAAAAA}\\AAAAAAA AAAAAAAAAA\\AAAAAAA ,name=10070116]
    [\textbf{AAAAA AAAAAA}\\AAAAAAA AAAAAAAAAA\\AAAAAAA ,name=10070118]
    ]
    [\textbf{AAAAAA AAAAAAA}\\AAAAAAAAAA AAAAAAA\\AAAAAAA ,name=10070081
    [\textbf{ZZZZZ ZZZZZZ}\\ZZZZZZZ\\ZZZZZZZ ZZZZZZZ\\ZZZZZZZ ,name=10070070
    [,phantom, minimum height=0ex]
    [\textbf{ZZZZZZZ ZZZZZ}\\ZZZZ ZZZZZZZZ\\ZZZZZZZ ,name=10070117]
    [\textbf{ZZZZZZZ ZZZZZ}\\ZZZZ ZZZZZZZZ\\ZZZZZZZ ,name=10070121]
    [\textbf{AAAAA AAAAAA}\\AAAA AAAAAAAA\\AAAAAAA ,name=10071097]
    ]
    % The children of the node below overlaps the children of the node above
    [\textbf{YYYYYY YYYYYYYY}\\YYYYYYYYYY YYYYYYY\\YYYYYYY ,name=10071027
    [,phantom, minimum height=0ex]
    [\textbf{YYYYY YYYYYYYY}\\YYYYYYYYYY YYYYYYYYYY\\YYYYYYY ,name=10070089]
    [\textbf{YYYYYYY Y YYYYYY}\\YYYYYYYYYY YYYYYYYYYY\\YYYYYYY ,name=10071317]
    ]
    [\textbf{AAAAAA AAAAAAAAAAAAAA}\\AAAAAAAAAA AAAAAAAAAA\\AAAAAAA ,name=10070059
    [,phantom]
    ]
    [\textbf{AAAA AAAAA}\\AAAA AAAAAAAA\\AAAAAAA ,name=10070061
    [,phantom]
    ]
    [\textbf{AAAAAAA AAAAAAAA}\\AAAA AAAAAAAA\\AAAAAAA ,name=10070078
    [,phantom]
    ]
    [\textbf{AAAAAAA AAAAAAAAA}\\AAAA AAAAAAAA\\AAAAAAA ,name=10070091
    [,phantom]
    ]
    [\textbf{AAAAAAA AAAAAA }\\AAAAAAAAAA AAAAAAAAAA\\AAAAAAA ,name=10070120
    [,phantom]
    ]
    ]
    [\textbf{AAAAAAA AAAAAAAAA}\\AA AAAAAAA\\AAAAAAA ,name=10070098
    [,phantom, minimum height=0ex]
    [\textbf{AAAA AAAA}\\AAAAAAA\\AAAA AAAAAAAAAA\\AAAAAAA ,name=10070105]
    [\textbf{AAAAA AAAAAAAA}\\AA AAAAA\\AAAAAAA ,name=10070111]
    [\textbf{AAAAAAA AAAAAAAA}\\AA AAAAAAAAAA\\AAAAAAA ,name=10070115]
    ]
    [\textbf{AAAA AAAAAAAAA}\\AAAAAAAA AAAA AAAAAAAAAA\\AAAAAAA ,name=10011825
    [,phantom]
    ]
    [\textbf{AAAAAAAA AAAAA}\\AAAAAAAAAA{,} AAA\\AAAAAAA,name=10070079
    [,phantom]
    ]
    ]
    ]
  \end{forest}
\end{document}

与基线对齐

相关内容