我正在尝试使用以下方法创建以下树forest
:
我得到了这个:
\documentclass{article}
\usepackage{forest, amsmath}
\begin{document}
\begin{forest}
for tree = {%
parent anchor = south,
child anchor = north,
s sep = 0em}
[, phantom
[, phantom
[h, no edge, tier = segment]
]
[{[$-$R]}, calign = first
[a, tier = segment]
[v, no edge, tier = segment]
[r, no edge, tier = segment]
]
[{[+R]}, calign = midpoint
[, parent anchor = north
[$\stackrel{*}{\text{u}}$, tier = segment]
[z, no edge, tier = segment]
[u, tier = segment]
]
[n, no edge, tier = segment]
[u, tier = segment]
[z, no edge, tier = segment]
]
[{[$-$R]}, calign = last
[d, no edge, tier = segment]
[$\stackrel{*}{\text{a}}$, tier = segment]
]
]
\end{forest}
\end{document}
看起来还不错,但我想改进两点:
h
第一个段和下一个段之间有很大的间隙a
(此外,底层所有段之间也有太多空间,但我可以忍受)。- 下方的分支结构
[+R]
理想情况下应该是直线,这样当树有分支时线的角度就不会改变。
我怎样才能实现这两件事?
答案1
您的愿望冲突。我们可以用来calign=fixed edge angles
拉直中间子树的边缘。但是,这将需要扩展子节点,这将增加最后一行字母之间的间距。
或者,我们可以保持终端子元素的间距或多或少固定,但边缘就不能是直的。
如果您需要两者,那么您可能必须假装。
\documentclass[border=10pt]{standalone}
\usepackage[linguistics]{forest}
\usepackage{amsmath}
\begin{document}
\begin{forest}
for tree={
s sep'=0em,
},
before typesetting nodes={
where content={}{child anchor=center, parent anchor=center}{},
where n children=0{tier=segment, inner sep=0pt}{},
},
[, phantom
[{[$-$R]}
[h, no edge]
[a, calign with current edge]
[v, no edge]
[r, no edge]
]
[{[+R]}, for tree={calign=fixed edge angles}
[
[$\stackrel{*}{\text{u}}$]
[z, no edge]
[u]
]
[n, no edge]
[u]
[z, no edge]
]
[{[$-$R]}
[d, no edge]
[$\stackrel{*}{\text{a}}$, calign with current edge]
]
]
\end{forest}
\begin{forest}
for tree={
s sep'=0em,
inner sep=0pt,
},
before typesetting nodes={
where content={}{coordinate}{},
where n children=0{tier=segment}{},
},
[, phantom
[{[$-$R]}
[h, no edge]
[a, calign with current edge]
[v, no edge]
[r, no edge]
]
[{[+R]}
[
[$\stackrel{*}{\text{u}}$]
[z, no edge]
[u]
]
[n, no edge]
[u]
[z, no edge]
]
[{[$-$R]}
[d, no edge]
[$\stackrel{*}{\text{a}}$, calign with current edge]
]
]
\end{forest}
\begin{forest}
for tree={
s sep'=0em,
inner sep=0pt,
},
before typesetting nodes={
where content={}{coordinate}{},
where n children=0{tier=segment}{},
},
[, phantom
[{[$-$R]}
[h, no edge]
[a, calign with current edge]
[v, no edge]
[r, no edge]
]
[{[+R]}, tikz+={
\draw [\forestoption{edge}] (.parent anchor) -- (!11.child anchor) coordinate [midway] (p) (p) -- (!1l.child anchor);
}
[, for tree={no edge}
[$\stackrel{*}{\text{u}}$]
[z]
[u]
]
[n, no edge]
[u]
[z, no edge]
]
[{[$-$R]}
[d, no edge]
[$\stackrel{*}{\text{a}}$, calign with current edge]
]
]
\end{forest}
\end{document}