这是我正在绘制的树。我想将左侧的括号(连同 x/y 树)移近 m/n 树。当我尝试使用“s sep”时,上面的 p/b 树也会移动。
\documentclass{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={forked edge, anchor=center}
[,phantom
[,for tree={grow'=east}
[, edge=rounded corners
[text
[example text text text text
[example text, name=f1]
[example text]
]
[example text, name=f2]
[example text]
]
[text
[, edge=rounded corners
[m, text=red, name=f3]
[n, text=red]
]
[, no edge
[example text, name=f4]
[example texts]
]
[, edge=rounded corners
[text, name=f5]
[example text
[text]
[text]
]
]
]
]
[, edge=rounded corners
[example text
[, edge=rounded corners
[text]
[text]
]
[, edge=rounded corners
[example text]
[example text
[example text]
[example text]
]
]
]
[example text]
]
]
[,for tree={grow'=west}, l=-42mm, s sep=0.5cm
[, name=p1]
[, name=p2]
]
[,for tree={grow'=east}, l=-4.2cm
[p]
[b]
]
[,for tree={grow'=west}, l=-2cm, s sep=0.5cm
[, name=p3, edge=rounded corners, edge=red]
[, name=p4, edge=rounded corners, edge=red]
]
[, for tree={grow'=east}, l=-2cm
[x, text=red, edge=red]
[y, text=red, edge=red]
]
]
\draw[-] (f1) to (p2);
\draw[-] (f2) to (p1);
\draw[-, red] (f3) to (p4);
\draw[-, red] (f4) to (p3);
\end{forest}
\end{document}
\end{document}
答案1
使用 xshift= <space>
。
\documentclass{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={forked edge, anchor=center}
[,phantom
[,for tree={grow'=east}
[, edge=rounded corners
[text1
[example text text text text
[example text, name=f1]
[example text]
]
[example text, name=f2]
[example text]
]
[text2
[, edge=rounded corners
[m, text=red, name=f3]
[n, text=red]
]
[, no edge
[example text, name=f4]
[example texts]
]
[, edge=rounded corners
[text, name=f5]
[example text
[text]
[text]
]
]
]
]
[, edge=rounded corners
[example text
[, edge=rounded corners
[text]
[text]
]
[, edge=rounded corners
[example text]
[example text
[example text]
[example text]
]
]
]
[example text]
]
]
[,for tree={grow'=west}, l=-42mm, s sep=0.5cm
[, name=p1]
[, name=p2]
]
[,for tree={grow'=east}, l=-4.2cm
[p]
[b]
]
[,for tree={grow'=west}, l=-1.67cm, s sep=0.5cm, xshift=-5cm,% changed <<<<
[, name=p3, edge=rounded corners, edge=green]
[, name=p4, edge=rounded corners, edge=green]
]
[, for tree={grow'=east, xshift=-5cm }, l=-1.67cm, % changed <<<<
[x, text=red, edge=red]
[y, text=red, edge=red]
]
]
\draw[-] (f1) to (p2);
\draw[-] (f2) to (p1);
\draw[-, red] (f3) to (p4);
\draw[-, red] (f4.east) to (p3); % changed <<<<
\end{forest}
\end{document}