我找到了一个很酷的解决方案,可以将类似表格的对象集成到forest
图形中(将森林中的树节点与表中的内容关联起来)但这与另一个修复树中三角形并插入平移的酷解决方案不兼容(为森林建造更小的屋顶)。
这就是我所拥有的。LaTeX 抱怨 GenericError...
\documentclass{article}
\usepackage{forest}
% to be able to do funny calculations for coordinates.
% used for the table explaining the topological model below the CP/IP/VP tree
\usetikzlibrary{calc}
% specification for all trees
\forestset{.style={for tree={parent anchor=south, child anchor=north,align=center,base=top}}}
% The following code fixes the size of triangles for examples with translations. The specification
% ",delay=with translation" at the leaves is important to make this work.
% https://tex.stackexchange.com/questions/167978/smaller-roofs-for-forest/205311#205311
\forestset{
with translation/.style={
l sep=0,inner xsep=0,
append translation/.expanded/.wrap pgfmath arg={\gettranslation{##1}}{content},
content/.expanded/.wrap pgfmath arg={\gettext{##1}}{content},
},
append translation/.style={append={[#1,no edge,l=0,inner xsep=0,inner ysep=0,outer ysep=0,before computing xy={l-=2pt}]}}
}
\def\gettext#1{\gettextA#1;;\endget}
\def\gettextA#1;#2;{\removesep#1;}
\def\gettranslation#1{\gettranslationA#1;;\endget}
\def\gettranslationA#1;#2;{\removesep#2;}
\def\removesep#1;#2\endget{#1}
% a specific style that specifies the word tier: all nodes that do not have any children
% to do: make this style default and change all other figures explicitely as is described here:
% https://tex.stackexchange.com/questions/167983/getting-rid-of-a-default-where-specification
\forestset{
sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=top},
where n children=0{tier=word,delay=with translation}{}
},
% auxiliary nodes without node label
empty nodes/.style={
delay={where content={}{shape=coordinate,for parent={for children={anchor=north}}}{}}}
}
\forestset{
terminus/.style={tier=word, for tree={fit=band}, for descendants={no path, align=left, l sep=0pt}},
no path/.style={edge path={}},
set me left/.style={calign with current edge, child anchor=north west, for parent={parent anchor=south west}},
}
%\usepackage{pstricks,pst-node}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{forest}
sn edges,empty nodes
[CP
[{}
[XP,terminus
[SpecCP\\prefield, name=p1
]
]
]
[C$'$
[{}
[C$^0$, terminus
[C0\\left SB, name=c0
]
]
]
[IP
[{}
[XP, terminus
[{IP (without I0, V0)\\middlefield}
[SpecIP\\subject position, set me left, name=specip
]
[phrases inside\\the VP, name=p3
]
]
]
]
[I$'$
[VP, name=vp
[V$^0$, name=v0, terminus, no path, anchor=east
[{V0, I0\\right SB}, name=p2, set me left
]
]
]
[{}
[I$^0$, terminus, name=io
]
]
]
]
]
]
\draw [thick]
(p1.north west) rectangle (io.east |- p3.south);
\draw
($(c0.north east)!1/2!(specip.west |- c0.north east)$) coordinate (p6) -- (p6 |- p3.south)
($(p1.north east)!1/2!(c0.north west)$) coordinate (p4) -- (p3.south -| p4)
($(specip.north east)!1/2!(p3.north west)$) coordinate (p5) -- (p3.south -| p5)
($(p2.north west)!1/2!(p2.north west -| p3.east)$) coordinate (p7) -- (p3.south -| p7)
(p6 |- p2.south) -- (p2.south -| p7)
(vp.south) -- (v0.center -| p3.west) -- (v0.west)
(v0.east) -- +(4.5pt,0) -- (vp.south)
;
\end{forest}
\caption{\label{Abb-GB-Topo}CP, IP and VP and the topological model of German}
\end{figure}
\end{document}
答案1
我认为,问题在于您实际上并不想with translation
将其应用于构成表格的节点。因此,您用于翻译的代码假设具有 0 个子节点的节点是正确的应用节点,with translation
但这是行不通的。您需要将其应用于标记terminus
为表格之前的最终节点的节点。
如果您希望将具有以下所有特征集的树组合在同一个文档中,则需要稍微小心一点:
- 具有翻译但没有表格的树 - 在这里我们希望在子节点数量为 0 时应用翻译内容,以避免必须自己标记终端节点;
- 有表格但没有翻译的树;
- 带有翻译和表格的树 - 在这里我们希望将翻译内容应用到标记的节点,
terminus
因为具有 0 个子节点的节点实际上可能是表格的一部分; - 用于
\trace
。
forest
以下代码演示了如何将它们组合成单个文档。在启动每棵树时,需要稍微介绍一下。这是通过使用样式来实现的。
- 没有表格的树:
sn edges, no tabular
启动树时使用。 - 用途
\trace
:将trace
样式添加到相关节点。 - 带表格的树:在启动树时单独使用,并使用除非如上所述使用,否则
sn edges
标记树部分的终端节点。(由于当前所有内容均已定义,因此您不能在跟踪节点下方有表格单元。)terminus
trace
您不能在将要应用的\trace
节点中使用with translation
,并且不能允许将其with translation
应用于应作为表格一部分的节点。
如果这看起来过于复杂,那么最简单的解决方案就是单独编译你的树,然后将图像包含在你的文档中。
\documentclass{article}
\usepackage{forest}
\forestset{
sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=top}},
no tabular/.style={sn edges, for tree={where n children=0{tier=word, delay=with translation}{}}},
trace/.style={
replace by={[\trace, delay={}, tier=word]}
},
terminus/.style={
tier=word,
delay=with translation,
for children={
tier=tabular,
},
for tree={
fit=band,
},
for descendants={
no path,
align=left,
l sep=0pt,
},
},
empty nodes/.style={
delay={where content={}{shape=coordinate,for parent={for children={anchor=north}}}{}}},
no path/.style={edge path={}},
set me left/.style={calign with current edge, child anchor=north west, for parent={parent anchor=south west}},
with translation/.style={
l sep=0,
inner xsep=0,
append translation/.expanded/.wrap pgfmath arg={\gettranslation{##1}}{content},
content/.expanded/.wrap pgfmath arg={\gettext{##1}}{content},
},
append translation/.style={
append={
[
#1,
no edge,
l=0,
inner xsep=0,
inner ysep=0,
outer ysep=0,
before computing xy={
l-=2pt
}
]
},
},
}
\def\gettext#1{\gettextA#1;;\endget}
\def\gettextA#1;#2;{\removesep#1;}
\def\gettranslation#1{\gettranslationA#1;;\endget}
\def\gettranslationA#1;#2;{\removesep#2;}
\def\removesep#1;#2\endget{#1}
\newcommand{\trace}{\raisebox{0.2ex}{\_}\rule{0cm}{0.7em}}
\begin{document}
\hfill
\begin{forest}
sn edges, no tabular
[NP
[Det [eine;a] ]
[N$'$
[A [kluge;smart] ]
[N$'$
[N [, trace ] ] ] ] ]
\end{forest}
\hfill
\begin{forest}
sn edges
[NP
[Det
[eine;a, terminus
[tab1, name=p1]
]
]
[N$'$
[A
[kluge;smart, terminus
[tab2, name=p2
]
]
]
[N$'$
[N
[, trace
]
]
]
]
]
\draw
(p1.north west) rectangle (p2.south east)
($(p1.north east)!1/2!(p2.north west)$) coordinate (p3) -- (p3 |- p2.south);
\end{forest}
\hfill
\bigskip
\begin{forest}
sn edges, empty nodes
[CP
[{}
[XP,terminus
[SpecCP\\prefield, name=p1
]
]
]
[C$'$
[{}
[C$^0$, terminus
[C0\\left SB, name=c0
]
]
]
[IP
[{}
[XP, terminus
[{IP (without I0, V0)\\middlefield}
[SpecIP\\subject position, set me left, name=specip
]
[phrases inside\\the VP, name=p3
]
]
]
]
[I$'$
[VP, name=vp
[V$^0$, name=v0, terminus, no path, anchor=east
[{V0, I0\\right SB}, name=p2, set me left
]
]
]
[{}
[I$^0$, terminus, name=io
]
]
]
]
]
]
\draw [thick]
(p1.north west) rectangle (io.east |- p3.south);
\draw
($(c0.north east)!1/2!(specip.west |- c0.north east)$) coordinate (p6) -- (p6 |- p3.south)
($(p1.north east)!1/2!(c0.north west)$) coordinate (p4) -- (p3.south -| p4)
($(specip.north east)!1/2!(p3.north west)$) coordinate (p5) -- (p3.south -| p5)
($(p2.north west)!1/2!(p2.north west -| p3.east)$) coordinate (p7) -- (p3.south -| p7)
(p6 |- p2.south) -- (p2.south -| p7)
(vp.south) -- (v0.center -| p3.west) -- (v0.west)
(v0.east) -- +(4.5pt,0) -- (vp.south)
;
\end{forest}
\end{document}