我正在尝试使用 tikz-qtree 包创建语法树图,但在树中放置箭头时遇到了问题。我尝试了几种解决方案,但都没有解决问题。这是我目前正在使用的代码:
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{tikzmark}
\tikzset{every tree node/.style={align=center,anchor=north}}
\tikzset{edge from parent/.append style={very thick}}
\begin{document}
\begin{tikzpicture}
\tikzset{level distance=30pt}
\tikzset{sibling distance=5pt}
\Tree [.IP \node(subj){Mary$_1$};
[.I$'$ \node(head_I){I};
[.AgrOP \node(obj){John$_2$};
[.AgrO$'$ \node(head-AgrO){AgrO};
[.VP [.VP \edge[roof]; {\subnode{t1}{t$_1$} entertained \subnode{t2}{t$_2$}} ]
[.PP \edge[roof]; {during his$_2$ vacation} ]]]]]]
\draw[thick, ->] (t1.south) to[out=-90,in=-90,looseness=1] (subj.south);
\draw[thick, dashed, ->] (t2.south) to[out=-90,in=-90,looseness=1] (obj.south);
\end{tikzpicture}
\end{document}
当我编译此代码时,连接跟踪节点 t1 和 t2 到其各自前因的箭头位置不正确。
我尝试过使用 tikzmark 库和\tikzmarknode
命令,\tikz[remember picture, baseline]
但是似乎没有帮助。
有人能帮我找出问题并提出解决方案以正确定位树状图中的箭头吗?
预先感谢您的帮助!
答案1
如果您想要使用该tikzmark
包,则需要将其添加[remember picture]
到您的tikzpicture
环境中。然后经过两次编译后,箭头应该来自正确的位置。
但我不会tikzmark
为此使用该包,而只是根据 VP 节点的锚点作为起点,并使用calc
库根据需要进行调整:
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{tikzmark}
\usetikzlibrary{calc}
\tikzset{every tree node/.style={align=center,anchor=north}}
\tikzset{edge from parent/.append style={very thick}}
\begin{document}
With \texttt{tikzmark}
\begin{tikzpicture}[remember picture]
\tikzset{level distance=30pt}
\tikzset{sibling distance=5pt}
\Tree [.IP \node(subj){Mary$_1$};
[.I$'$ \node(head_I){I};
[.AgrOP \node(obj){John$_2$};
[.AgrO$'$ \node(head-AgrO){AgrO};
[.VP [.VP \edge[roof]; {\subnode{t1}{t$_1$} entertained \subnode{t2}{t$_2$}} ]
[.PP \edge[roof]; {during his$_2$ vacation} ]]]]]]
\draw[thick, ->] (t1.south) to[out=-90,in=-90,looseness=1] (subj.south);
\draw[thick, dashed, ->] (t2.south) to[out=-90,in=-90,looseness=1] (obj.south);
\end{tikzpicture}
Without \texttt{tikzmark}
\begin{tikzpicture}
\tikzset{level distance=30pt}
\tikzset{sibling distance=5pt}
\Tree [.IP \node(subj){Mary$_1$};
[.I$'$ \node(head_I){I};
[.AgrOP \node(obj){John$_2$};
[.AgrO$'$ \node(head-AgrO){AgrO};
[.VP [.VP \edge[roof]; \node(VP){$t_1$ entertained t$_2$}; ]
[.PP \edge[roof]; {during his$_2$ vacation} ]]]]]]
\draw[thick, ->] (VP.south west) to[out=-110,in=-90,looseness=1] (subj.south);
\draw[thick, dashed, ->] ($(VP.south east)-(.25,0)$) to[out=-85,in=-90,looseness=1] (obj.south);
\end{tikzpicture}
\end{document}
答案2
\subnode
,如果使用得当,它们会按预期工作。必须是整个画面的一个选项。几乎可以肯定,您只想将其remember picture
用于弯曲的箭头。应该像在代码中一样使用 s。overlay
remember picture
overlay
\subnode
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{tikzmark}
\tikzset{every tree node/.style={align=center,anchor=north}}
\tikzset{edge from parent/.append style={very thick}}
\begin{document}
\begin{tikzpicture}[remember picture]
\tikzset{level distance=30pt}
\tikzset{sibling distance=5pt}
\Tree [.IP \node(subj){Mary$_1$};
[.I$'$ \node(head_I){I};
[.AgrOP \node(obj){John$_2$};
[.AgrO$'$ \node(head-AgrO){AgrO};
[.VP [.VP \edge[roof]; {\subnode{t1}{t$_1$} entertained \subnode{t2}{t$_2$}} ]
[.PP \edge[roof]; {during his$_2$ vacation} ]]]]]]
\draw[overlay,thick, ->] (t1.south) to[out=-90,in=-90,looseness=1] (subj.south);
\draw[overlay,thick, dashed, ->] (t2.south) to[out=-90,in=-90,looseness=1] (obj.south);
\end{tikzpicture}
\end{document}