5

I'm drawing trees with TikZ and

\begin{tikzpicture}
    \node {$C$}
        child[missing]
 child{node {$i$}
 child[missing]
 child{node {$j$}}
    };
\end{tikzpicture}

produces edges that don't line up as I want them to. If I were to draw circles around the nodes, an edge goes from the bottom center of the parent's circle to the top center of the child's, making the arm appear jagged. I've tried moving the anchors around, but that wasn't it. What I want seems to occur automatically in the examples in the pgf manual (see the final tree example on page 192). What am I not doing?

1
  • 1
    Could you please add a picture of what you are trying to achieve.
    – Caramdir
    Commented Sep 30, 2010 at 22:55

2 Answers 2

6

Not quite sure what's going on here. Have you altered the default parent and child anchors?

Here are 3 examples:

\begin{tikzpicture}[parent anchor=south,child anchor=north,every  node/.style={circle,draw}]
\node {$C1$}
    child[missing]
    child{node {$i$}
        child[missing]
        child{node {$j$}}
        };
\end{tikzpicture}
\begin{tikzpicture}[parent anchor=center,child anchor=center,every  node/.style={circle,draw}]
\node {$C2$}
    child[missing]
    child{node {$i$}
        child[missing]
        child{node {$j$}}
        };
\end{tikzpicture}
\begin{tikzpicture}[every node/.style={circle,draw}]
\node {$C3$}
    child[missing]
    child{node {$i$}
        child[missing]
        child{node {$j$}}
        };
\end{tikzpicture}

which produce:

Three trees

Now, your example (my C3) appears to be the best; is it C1 you're looking for?

2
  • I wanted C3, but was getting C1 with the same code. For whatever reason, deleting \usetikzlibrary{tikz-qtrees} (which I don't need--it was left from an earlier tree-drawing experiment) solves the problem. I assume it changes the anchors.
    – hoyland
    Commented Oct 2, 2010 at 0:49
  • I had the same problem as @holyland. I desperately tried changing anchors and everything else which came to my mind and in the end removing "tikz-qtrees" did the trick. thanks!
    – wuqui
    Commented Jun 29, 2015 at 16:17
1

Trees do well in forests...

\documentclass[tikz,a4paper,border=5pt]{standalone}
\usepackage{forest}

\begin{document}

\begin{forest}
  for tree={
    math content,
    circle,
    draw
  }
  [C3
    [, phantom]
    [i
      [, phantom]
      [j
      ]
    ]
  ]
\end{forest}

\end{document}

<code>forest</code> tree

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .