我想要将节点 [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
缺失边。您可以使用,将 设置y
为Bye3
与 相同。Bye
before 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}