我写了一个样式,forest
可用于将树节点与其左侧和右侧的兄弟节点连接起来。这对于像下面这样的情况非常有用。
现在我想连接顶层的两个节点(基本上是两棵完整的树)。我在两个节点的顶部引入了一个节点,并将其声明为幻像节点。由于我不明白的原因,两个女儿之间的联系没有被绘制出来:
如果我用真实节点替换幻影节点,一切都很好:
我怎样才能摆脱最顶层的 V 节点并保留其余部分?
\documentclass{article}
\usepackage{forest}
\forestset{dg edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom},
where n children=0{tier=word,edge=dotted,calign with current edge}{}
},
dg junction/.style={edge path={\noexpand\path[\forestoption{edge}]
(!p.east)--(!.west) (.east)--(!n.west)\forestoption{edge label};}} }
\begin{document}
\begin{forest}
dg edges
[V %,phantom
[V, l sep+=2ex, name=v1
[N,name=n1 [Robin]]
[came]
[Part [in] ] ]
[Conj,dg junction [and]]
[V, l sep+=2ex, name=v2 [found]
[N
[Det [a]]
[chair]]
[P, name=p [in]
[N
[Det [thirty]]
[seconds]]]
]]
\draw (v2.south)--(n1.north)
(v1.south)--(p.north);
\end{forest}
\end{document}
编辑:
发生以下情况\phantom{V}
:
\documentclass{article}
\usepackage{forest}
\forestset{dg edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom},
where n children=0{tier=word,edge=dotted,calign with current edge}{}
},
dg junction/.style={edge path={\noexpand\path[\forestoption{edge}]
(!p.east)--(!.west) (.east)--(!n.west)\forestoption{edge label};}} }
\begin{document}
bla, bla, bla, bla,bla, bla,bla, bla,bla, bla,bla, bla,bla, bla,bla, bla,bla, bla,bla, bla,bla, bla,
\begin{forest}
dg edges
[\phantom{V}
[V, l sep+=2ex, name=v1
[N,name=n1 [Robin]]
[came]
[Part [in] ] ]
[Conj,dg junction [and]]
[V, l sep+=2ex, name=v2 [found]
[N
[Det [a]]
[chair]]
[P, name=p [in]
[N
[Det [thirty]]
[seconds]]]
]]
\draw (v2.south)--(n1.north)
(v1.south)--(p.north);
\end{forest}
\end{document}
如果我添加no edge
V 节点,边就消失了,但幻影节点的空间仍然存在。除了顶部的边被隐藏外,该图如下所示:
答案1
edge path
无效,因为父级是phantom
,这实际上意味着no edge
子级也是如此。请tikz
改用以下键:
\documentclass[tikz, border=5pt]{standalone}
\usepackage{forest}
\forestset{
dg edges/.style={
for tree={
parent anchor=south,
child anchor=north,
align=center,base=bottom},
where n children=0{
tier=word,
edge=dotted,
calign with
current edge
}{}
},
dg junction/.style={
tikz={
\path[\forestoption{edge}] (!p.east)--(!.west) (.east)--(!n.west);
},
% no edge,% uncomment if you never want edges with this style
}
}
\begin{document}
\begin{forest}
dg edges
[,phantom
[V, l sep+=2ex, name=v1
[N,name=n1 [Robin]]
[came]
[Part [in] ] ]
[Conj,dg junction [and]]
[V, l sep+=2ex, name=v2 [found]
[N
[Det [a]]
[chair]]
[P, name=p [in]
[N
[Det [thirty]]
[seconds]]]
]]
\draw (v2.south)--(n1.north)
(v1.south)--(p.north);
\end{forest}
\end{document}
正如 Stefan Müller 在问题讨论中指出的那样,要在父级不是 时使用相同的样式phantom
,您需要添加显式的no edge
,除非当然您希望tikz
和edge
要绘制的路径。