我是森林包的新手,我创建了一棵树,两个节点之间有一个节点,该节点不在中心。在图片中,它是根下面的 ZS(A; C)。这是代码:
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{forest}
\begin{document}
\tikzset{>=latex}
\begin{forest} for tree={align=center}
[TH(3; A; B; C), for children={l+=2ex}
[TH(2; A; C; B)
[TH(1; A; B; C)
[ZS(A; C)]
]
[ZS(A; B)]
[TH(1; C; A; B)
[ZS(C; B)]
]
]
[ZS(A; C)]
[TH(2; B; A; C)
[TH(1; B; C; A)
[ZS(B; A)]
]
[ZS(B; C)]
[TH(1; A; B; C
[ZS(A; C)]
]
]
]
\end{forest}
\end{document}
我究竟做错了什么?
答案1
这是因为forest
计算节点位置,如上所述手册第 43f 页:
例如,请考虑下面的手动校正。默认情况下,B 比 C 更靠近 A,因为打包是从第一个子元素到最后一个子元素进行的 — 如果没有 C,B 的位置将保持不变。在正确的时刻调整 s,很容易将 B 置于 A 和 C 之间。
它继续建议添加before computing xy={s/.average={s}{siblings}}
非中心节点,如下所示:
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{forest}
\begin{document}
\tikzset{>=latex}
\begin{forest} for tree={align=center}
[TH(3; A; B; C), for children={l+=2ex}
[TH(2; A; C; B)
[TH(1; A; B; C)
[ZS(A; C)]
]
[ZS(A; B)]
[TH(1; C; A; B)
[ZS(C; B)]
]
]
[ZS(A; C), before computing xy={s/.average={s}{siblings}}]
[TH(2; B; A; C)
[TH(1; B; C; A)
[ZS(B; A)]
]
[ZS(B; C)]
[TH(1; A; B; C
[ZS(A; C)]
]
]
]
\end{forest}
\end{document}