6

I'm drawing a binary tree using tikz-qtree. In my binary tree the order of children is important, so I need distinguish which edge is the left one and the right one. In my sample code I can't distinguish if the node 1 is left or right. There is a way to specify this?

\documentclass[demo]{article}
\usepackage{tikz,tikz-qtree}
\begin{document}
\begin{figure}[ht]\begin{center}\begin{tikzpicture}[grow'=up]
\Tree [.\node(8){8}; 
       [.\node(5){5}; 
              [.\node(3){3}; 
                 \node(1){1}; ]
                \node(6){6}; ] 
             \node(12){12}; ]
\end{tikzpicture}\end{center}\end{figure}
\end{document}

enter image description here

5

You can specify edges explicitly when needed, and specify [draw=none]. I've also simplified your tree: you don't need to enclose every node in a \node command unless you have independent reasons for referring to them. For this kind of tree, it might be helpful to make every node a uniform size, so that the sibling distances don't vary. You can do this by setting a minimum size for the every tree node/.style. I've given a second tree showing how this can be done. In a single tree, you could add the option to the {tikzpicture} environment itself instead of using \tikzset.

\documentclass{article}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}[grow'=up]
\Tree [.8 
        [.5 
            [.3 
                \edge[]; {1}
                \edge[draw=none]; {}  ]
             6  ] 
          12 ]
\begin{scope}[xshift=2in]
\tikzset{every tree node/.style={minimum width=2em}}
\Tree [.8 
        [.5 
            [.3 
                \edge[]; {1}
                \edge[draw=none]; {}  ]
             6  ] 
          12 ]
\end{scope}   
\end{tikzpicture}
\end{document}

output of code

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.