3

How to make the edges from x (resp. y) to connect to the north anchors of the triangular leaf nodes A and B (resp. C)?

Note that this should not change the edge style between x and y. Therefore, the solution with edge from parent path = {(\tikzparentnode) -- (\tikzchildnode.north)} is unsatisfactory.

qtree-triangle-node

\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}
hengxin
  • 2,371

1 Answers1

4

You can add an explicit edge from parent path to your edge between x and y and use the .north path for the rest:

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

output of code

Alan Munn
  • 218,180