使用tikz-qtree
,两个分支均来自 'S.south'(左图)。如何像右图一样手动(或自动)指定这些分支位置?
\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[every node/.style = {draw, rectangle}]
% using tikz-qtree: both branches are from "S.south"
\Tree [.S [.NP ]
[.VP ]
]
% desired: both branches are not from ''s.south''
\begin{scope}[xshift = 2.5cm]
\node (s) {S};
\node (np) [below left = 0.50cm and 0.05cm of s] {NP};
\node (vp) [below right = 0.50cm and 0.05cm of s] {VP};
\draw (s) to (np);
\draw (s) to (vp);
\end{scope}
\end{tikzpicture}
\end{document}
答案1
我发现
edge from parent/.style= {draw,
edge from parent path = {(\tikzparentnode) -- (\tikzchildnode)}}
作品。
\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[every node/.style = {draw, rectangle},
edge from parent/.style= { % added code
draw, edge from parent path = {(\tikzparentnode) -- (\tikzchildnode)}},]
% using tikz-qtree
\Tree [.S [.NP ]
[.VP ]
]
% desired: both branches do not come from ''s.south''
\begin{scope}[xshift = 2.5cm]
\node (s) {S};
\node (np) [below left = 0.50cm and 0.05cm of s] {NP};
\node (vp) [below right = 0.50cm and 0.05cm of s] {VP};
\draw (s) to (np);
\draw (s) to (vp);
\end{scope}
\end{tikzpicture}
\end{document}