答案1
这是基于手册第 4 节中的示例进行的尝试forest
。
解决方案的一个优点forest
是可以轻松地在树的样式之间切换,例如具有直边的更传统的外观,甚至是倒挂。
\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={
s sep=1.5em,
l sep=5em,
text depth=0.5em,
text height=1em,
font=\itshape,
parent anchor=south,
child anchor=north,
% for the empty nodes
delay={where content={}{shape=coordinate,for parent={for children={anchor=north}}}{}},
% for the curved edges
edge path={
\noexpand\path[\forestoption{edge}]
(\forestOve{\forestove{@parent}}{name}.parent anchor)
.. controls +(0,0) and +(0,5em) .. % same as l sep
\forestoption{edge label}
(\forestove{name}.child anchor);
}
},
foo/.style n args=3{edge label={node[pos=0.8, font=\scshape, auto=#1, anchor=#2]{#3}}},
ll/.style={foo={left}{east}{#1}},
lr/.style={foo={right}{west}{#1}},
[
[persuade,ll=pred]
[John,ll=subj]
[Mary,lr=obj,for tree={l sep-=1em}
[,name=a]
]
[,lr=xcomp,s sep=2.5em % add fit=band if you want even more space
[behave,ll=pred]
[,ll=subj,tikz={\draw () to[out=270,in=270] (a);}]
[herself,lr=obj]
]
]
\end{forest}
\end{document}
答案2
这是使用默认 TikZ 树的尝试。虽然我实际上更喜欢的语法forest
(它也比 TikZ 本身做得更好),但我无法让arc down to
工作,forest
除非淹没在丑陋的 海洋中\noexpand
。“神奇”数字.551
。论文中的阿列克萨斯·里斯库斯使用贝塞尔曲线近似圆弧。
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{calc,quotes}
\begin{document}
\begin{tikzpicture}[every child node/.style={font=\itshape, anchor=base},
every child/.style={path label=},
arc down to/.style={to path={
let \p1=(\tikztostart),\p2=(\tikztotarget),
\n1={(\x2-\x1)*0.551}, \n2={(\y1-\y2)*0.551} in
(\p1) .. controls +(\n1,0) and +(0,\n2) .. (\p2) \tikztonodes
}},
edge from parent path={
(\tikzparentnode.south) edge [arc edge node/.try, arc down to]
(\tikzchildnode.north)
},
semicircle under to/.style={to path={
let \p1=(\tikztostart),\p2=(\tikztotarget)
in arc (180:360:\x2/2-\x1/2)
}},
path label/.style={arc edge node/.style={#1}},
level distance=0.75in,
sibling distance=0.75in,
level 2/.style={sibling distance=0.625in}]
\node [coordinate] {}
child [path label="PRED"'] { node {persuade} }
child [path label="SUBJ"' near end] { node {John} }
child [path label="OBJ"' near end] { node (mary) {Mary} }
child [path label="XCOMP", sibling distance=1in] {
node [coordinate] (x) {}
child [path label="PRED"' near end] { node {behave} }
child [path label="SUBJ"' near end] { node [coordinate] (subj) {} }
child [path label="OBJ"] { node {herself} }
};
\draw (mary.south) -- (mary.south |- subj) to [semicircle under to] (subj);
\end{tikzpicture}
\end{document}