例如,在下面的例子中,我希望level distance=32pt
仅为 PP 子树进行设置。
\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz, tikz-qtree}
\begin{document}
\begin{tikzpicture}
\Tree [.S [.NP [.Det the ] [.N cat ] ]
[.VP [.V sat ]
[.PP [.P on ]
[.NP [.Det the ] [.N mat ] ] ] ] ]
\end{tikzpicture}
\end{document}
我希望[.\node[level distance=32pt]{PP}; [.P on ]
它能起作用,但是却不行。
答案1
这里有两个连通的子树。第一个子树以level distance=30pt
开始,第二个子树PP
以level distance=60pt
(这就是我对你的问题的解释)
\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz, tikz-qtree}
\begin{document}
\begin{tikzpicture}
\tikzset{level distance=30pt}
\Tree [.S [.NP [.Det the ] [.N cat ] ]
[.\node(e3){VP}; [.V sat ]]]
\begin{scope}[shift={(60pt,-60pt)}]
\tikzset{level distance=60pt}
\Tree [.\node(e4){PP}; [.P on ]
[.NP [.Det the ] [.N mat ] ]]
\end{scope}
\draw (e3.south)--(e4);
\end{tikzpicture}
\end{document}
或者
使用
\begin{tikzpicture}
\tikzset{level distance=30pt}
\Tree [.S [.NP [.Det the ] [.N cat ] ]
[.\node(e3){VP}; [.V sat ]]]
\begin{scope}[shift={(60pt,-90pt)}]
\tikzset{level distance=30pt}
\Tree [.\node(e4){PP}; [.P on ]
[.NP [.Det the ] [.N mat ] ]]
\end{scope}
\draw (e3.south)--(e4);
\end{tikzpicture}
答案2
欢迎来到 TeX.SE!
你关注后会吗?
通过使用包可以轻松获得forest
:
\documentclass[tikz, border=3.141592]{standalone}
\usepackage[linguistics]{forest}
\begin{document}
\begin{forest}
for tree = {text depth=3pt,
inner sep=0pt,
anchor=north
}
[S
[NP
[Det[the ]]
[N [cat ]]
]
[VP
[V
[sat , tier=L]
]
[PP, fit=band, tier=L
[P [on ]]
[NP [Det [the ] ]
[N [mat ] ]
]
]
]
]
\end{forest}
\end{document}