5

I am trying to produce a binary tree using Tikz-qtree, however I am trying to figure out a way to shift my leaf node so that the top of the triangle connects to the edge. I tried using yshift on the node itself, but the edge is still connected to the same position.

The following code:

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{positioning,babel,shadows,trees,backgrounds,fit,arrows,shapes.geometric}   


\begin{document}

\tikzset{every tree node/.style={minimum size=10mm,inner sep=0pt,draw,circle, line width=1mm,font=\Large},
         edge from parent/.style=
         {draw, edge from parent path={(\tikzparentnode) -- (\tikzchildnode)}},
         level distance=2cm, sibling distance=.5cm}




\begin{tikzpicture}
\Tree [.~ \node[inner sep=10pt, regular polygon, regular polygon sides=3]{~}; \node[inner sep=10pt, regular polygon, regular polygon sides=3](b1){~}; ] 
\end{tikzpicture}

\end{document}

produces this image: enter image description here

However, I want to change it to something like this: enter image description here

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Martin Schröder Jul 10 '17 at 5:43
  • Use Forest with child anchor=parent (or child anchor=north` for older versions). – cfr Jul 11 '17 at 20:22
  • @MartinSchröder The OP seems to be doing pretty well with the format. Looks like a fine first post to me. [I know this is a standard comment, but it carries the implication 'you obviously aren't familiar with our format', which is OK if true, but confusing, if not.] – cfr Jul 11 '17 at 20:24
5

You can change the edge from parent path option to:

edge from parent path={(\tikzparentnode) -- (\tikzchildnode.north)}

to obtain:

output

(probably it will look better if you move your triangles nodes a bit further down).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.