如何连接 tikz-qtree 中三角形(叶)节点的北锚点?

如何连接 tikz-qtree 中三角形(叶)节点的北锚点?

如何使来自x(分别y)的边连接到三角形叶节点AB(分别C)的北锚点?

请注意,这不会改变x和之间的边样式y。因此,解决方案并不edge from parent path = {(\tikzparentnode) -- (\tikzchildnode.north)}令人满意。

qtree 三角形节点

\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}

代码输出

相关内容