如何使来自x
(分别y
)的边连接到三角形叶节点A
和B
(分别C
)的北锚点?
请注意,这不会改变x
和之间的边样式y
。因此,解决方案并不edge from parent path = {(\tikzparentnode) -- (\tikzchildnode.north)}
令人满意。
\documentclass[tikz]{standalone}
\usepackage{tikz-qtree}
\usetikzlibrary{positioning, shapes.geometric}
\begin{document}
\begin{tikzpicture}[level distance = 35pt, sibling distance = 20pt,
edge from parent/.style = {
draw, edge from parent path = {(\tikzparentnode) -- (\tikzchildnode)}}]
\tikzset{every internal node/.style = {draw, circle, red, font = \Large}}
\tikzset{every leaf node/.style = {draw, blue, regular polygon, regular polygon sides = 3, inner sep = 1pt}}
\Tree [.$y$
\edge [red, very thick];
[.$x$
$A$
$B$
]
$C$
]
\end{tikzpicture}
\end{document}
答案1
您可以edge from parent path
在 x 和 y 之间向边缘添加一个显式路径,然后使用该.north
路径处理其余部分:
\documentclass[tikz]{standalone}
\usepackage{tikz-qtree}
\usetikzlibrary{positioning, shapes.geometric}
\begin{document}
\begin{tikzpicture}[level distance = 35pt, sibling distance = 20pt,
edge from parent/.style = {
draw, edge from parent path = {(\tikzparentnode) -- (\tikzchildnode.north)}}]
\tikzset{every internal node/.style = {draw, circle, red, font = \Large}}
\tikzset{every leaf node/.style = {draw, blue, regular polygon, regular polygon sides = 3, inner sep = 1pt}}
\Tree [.$y$
\edge [red, very thick,edge from parent path = {(\tikzparentnode) -- (\tikzchildnode)}];
[.$x$
$A$
$B$
]
$C$
]
\end{tikzpicture}
\end{document}