答案1
也许是这样的?
\documentclass{article}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={forked edge, fork sep=0pt, anchor=center
}
[{}, for tree={grow'=east}
[x]
[y]
]
\draw[<-] (.parent anchor) -- ++(-.5,0) node[midway, above] {a} node[midway, below] {b};
\end{forest}
\end{document}
您还可以执行以下操作:
\begin{forest}
for tree={forked edge, fork sep=0pt, anchor=center, child anchor=west
}
[{}, for tree={grow'=east}
[x
[]
[]
]
[y]
]
\draw[<-] (.parent anchor) -- ++(-.5,0) node[midway, above] {a} node[midway, below] {b};
\draw[<-] (!1.child anchor) -- ++(-.5,0) node[midway, above] {a} node[midway, below] {b};
\end{forest}
更新:
使用\forestset
,还可以创建自定义边,使用方式如下:
\documentclass{article}
\usepackage[edges]{forest}
\forestset{
arrow/.style 2 args={
edge path={
\noexpand\path[\forestoption{edge},->]
(!u.parent anchor) -- ++(\forestoption{fork sep},0)
\forestoption{edge label} node[midway,above]{#1} node[midway,below]{#2};
\noexpand\path[\forestoption{edge}]
([xshift=\forestoption{fork sep}]!u.parent anchor) |- (.child anchor)
\forestoption{edge label};
}
}
}
\begin{document}
\begin{forest}
for tree={forked edge, fork sep=.5cm, anchor=center, child anchor=west
}
[{}, for tree={grow'=east}
[x, arrow={a}{b}
[z, arrow={c}{d}]
[]
]
[y]
]
\end{forest}
\begin{forest}
for tree={forked edge, l=2cm, fork sep=1.5cm, anchor=center, child anchor=west
}
[{}, for tree={grow'=east}
[x, arrow={longer}{words}
[z, arrow={other}{stuff}]
[]
]
[y]
]
\end{forest}
\end{document}
fork sep
您可以使用和选项更改距离l
: