如何将森林中的两个节点合并为一个?

如何将森林中的两个节点合并为一个?

我想要将节点 [Bye1 和 Bye2] 合并为以下 MWE 中的 Bye 3。

 \documentclass[tikz,border=10pt]{standalone}
 \usepackage[edges]{forest}
\begin{document}
\begin{forest}
  forked edges,
  for tree={
           l sep+=5pt,
             inner sep=1.5pt,
              grow'=east,
            font=\sffamily, edge+={darkgray, line width=1pt}, draw=darkgray, align=center, anchor=children},
  before packing={where n children=3{calign child=2, calign=child edge}{}},
  before typesetting nodes={where content={}{coordinate}{}},
  where level<=0{line width=1pt}{line width=1pt},
  [Testing 
[Hello,
] 
[Bye, 
[Bye1]
[Bye2]
]
    ]
\end{forest}
\end{document}

答案1

使Bye3节点成为 的子节点Bye2,然后是\draw缺失边。您可以使用,将 设置yBye3与 相同。Byebefore drawing tree={y=y("!uu")}

在此处输入图片描述

\documentclass[tikz,border=10pt]{standalone}
 \usepackage[edges]{forest}
\begin{document}
\begin{forest}
  forked edges,
  for tree={
           l sep+=5pt,
             inner sep=1.5pt,
              grow'=east,
            font=\sffamily, edge+={darkgray, line width=1pt}, draw=darkgray, align=center, anchor=children},
  before packing={where n children=3{calign child=2, calign=child edge}{}},
  before typesetting nodes={where content={}{coordinate}{}},
  where level<=0{line width=1pt}{line width=1pt},
[Testing 
    [Hello] 
    [Bye, 
        [Bye1, name=B1]
        [Bye2
            [Bye3, name=B3, before drawing tree={y=y("!uu")}]
        ]
    ]
]
\draw[darkgray, line width=1pt] (B1.east)--++(\forestoption{fork sep},0)|-(B3);
\end{forest}
\end{document}

相关内容