我经常想绘制如下的示意图树。
这些不适用于当前roof
选项,forest
因为我经常需要roof
扩展到多个节点。
看起来当前roof
代码将屋顶绘制为从子节点向上的边缘路径,这意味着屋顶的底部roof
只覆盖一个节点:
\forestset{
roof/.style={edge path'={%
(.parent first)--(!u.children)--(.parent last)--cycle
}
},
}
是否有一些简单/优雅的方法可以roof
覆盖多个节点?
编辑以添加 MnWE(最小非工作示例)
以下是我现在能做的最好的事情:
\documentclass{article}
\usepackage[linguistics]{forest}
\begin{document}
\begin{forest}
[XP,
[node1]
[YP, roof % triangle will be drawn between YP and XP
[node2, roof] % triangle will be drawn between node2 and YP
]
]
\end{forest}
\end{document}
理想情况下,最好有某种修饰符,比如downroof
从父级到所有直属子级绘制三角形,如下所示:
\begin{forest}
[XP, downroof % ideally will draw triangle to cover node1 and YP
[node1]
[YP, downroof % ideally will draw triangle to cover node2
[node2]
]
]
\end{forest}
答案1
downroof
绘制一个横跨所有子节点的屋顶:
\documentclass[border=10pt]{standalone}
\usepackage[linguistics]{forest}
\forestset{
downroof/.style={
for children={
if n=1{
edge path'={
(.parent first) -- (!u.parent anchor) -- (!ul.parent last) -- cycle
}
}{no edge}
}
}
}
\begin{document}
\begin{forest}
[XP, downroof % ideally will draw triangle to cover node1 and YP
[node1]
[YP, downroof % ideally will draw triangle to cover node2
[node2]
]
]
\end{forest}
\end{document}