[Tex/LaTex] Tikz tree and position of single leaf in binary tree

positioningtikz-pgftikz-treestrees

I am constructing a binary tree which looks as follows:

\begin{tikzpicture}
\node {root}
    child {  node {left}   }
    child {  node {right}
                    child { node {rightmost} }
             }  ;
\end{tikzpicture}

screenshot

In case of single children, as is the case with "rightmost", the edges are just pointing down. I'd like to influence the position of the single edge and node so that they are slanted as if they had a sibling:

screenshot

How would I do that?

Best Answer

One way is to use the missing option. This method is probably the most natural considering what you want to achieve : "as if there was a sibling".

\begin{tikzpicture}
\node {root}
    child {  node {left}   }
    child {  node {right}
                    child[missing] {node {}}
                    child { node {rightmost} }
             }  ;
\end{tikzpicture}

Output :

output2

The following code does the trick as well, making use of the right option.

\begin{tikzpicture}
\node {root}
    child {  node {left}   }
    child {  node {right}
                    child[right] { node {rightmost} }
             }  ;
\end{tikzpicture}

And the output :

output

Note that the alignment of edges looks better with the first option. The reason is that missing is a tree-specific option, which asks tikz to act "as if there was a sibling", and as such it doesn't depend on the content of the nodes for the alignment.

On the other hand, as I understand it, right is an option which is passed to the node, and has it placed relatively to its leftmost edge, instead of its center. This option doesn't affect the rest of the tree nor depend on it, that's why the output is less satisfying.

Related Question