Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Welcome to TeX.SE! –  cmhughes Nov 23 '12 at 19:11
add comment

1 Answer

up vote 9 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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