![一个森林节点有可能有多个父节点吗?](https://linux22.com/image/467049/%E4%B8%80%E4%B8%AA%E6%A3%AE%E6%9E%97%E8%8A%82%E7%82%B9%E6%9C%89%E5%8F%AF%E8%83%BD%E6%9C%89%E5%A4%9A%E4%B8%AA%E7%88%B6%E8%8A%82%E7%82%B9%E5%90%97%EF%BC%9F.png)
我有这片森林:
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage[edges]{forest}
\usepackage{linguex}
\begin{forest}
for tree={
draw,
align=center
},
forked edges,
[A,name=CEO
[B
[C]
[D,draw,red,name=ME]
]
]
\draw[-] (CEO) to[out=east,in=east] (ME);
\node [draw, fit=(current bounding box.south east) (current bounding box.north west)] {};
\end{forest}
这给了我这个:
粗略地看一下forest
文档,我找不到如何使 D 成为和的子B
项A
。
我唯一发现的就是这个,\draw[-] (CEO) to[out=east,in=east] (ME);
但是我觉得它特别丑,所以我希望它像这个美人鱼图(当然是带有直线的):
flowchart TD;
A --- B;
B --- C;
B --- D;
A --- D;
答案1
您可以使用ext.paths.ortho
(部分tikz-ext库)在节点之间绘制直线。这里我们使用锯齿形路径r-rl
,其中的rl
解释是先向右,然后垂直,然后向左。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage[edges]{forest}
\usetikzlibrary{ext.paths.ortho}
\begin{document}
\begin{forest}
for tree={
draw,
align=center
},
forked edges,
[A,name=CEO
[B
[C]
[D,draw,red,name=ME]
]
]
\draw (CEO.east) r-rl (ME.east);
\end{forest}
\end{document}