# How to modify the distance between branches when drawing trees using TiKZ?

I want to modify the distance between a parent node and a child node when drawing a tree using TiKZ package. I looked at the example at TiKZ site, and add a property called sibling distance. However, no matter where I added (parent and child), it points to a wrong place.

As we can see, if I add more children to node 2, it will overlap with 5. Adding a sibling distance yield even a worse result:

And I couldn't figure out what caused this issue. Any idea? Thank you.

Minimal Example

\documentclass[a4paper,landscape]{scrartcl}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[auto]
\node [circle,draw] (z){0}
child { [sibling distance=10mm]
node[circle,draw] (a) {1}
child {
node[circle,draw] (c) {5}
}
child {
node[circle,draw] (d) {5}
}
child {
node[circle,draw] (e) {5}
}
child {
node[circle,draw] (f) {5}
}
}
child {
node[circle,draw] (b) {2}
}
;

\path (z) -- (a);
\path (z) -- (b);
\path (a) -- (c);
\end{tikzpicture}
\end{document}

-
 sibling distance sets the distance between siblings. I think you are looking for level distance. – Seamus Aug 15 '11 at 11:44 I'm not sure exactly what you want. Maybe you could clarify your question? Does adding e.g. [sibling distance=50mm] to the end of the line \node [circle,draw] (z){0} achieve what you want? – N.N. Aug 15 '11 at 11:48 @Seamus: I set level distance but it was still the same. Thank you though. – Chan Aug 15 '11 at 12:01 @Jake: Thanks for pointing that out. Edited. – Chan Aug 15 '11 at 12:28

You can change the sibling distance for each level of the tree individually, using level <number>/.style={sibling distance=<value>}:

\documentclass[a4paper,landscape]{scrartcl}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[
auto,
level 1/.style={sibling distance=40mm},
level 2/.style={sibling distance=10mm}]
\node [circle,draw] (z){0}
child {
node[circle,draw] (a) {1}
child {
node[circle,draw] (c) {5}
}
child {
node[circle,draw] (d) {5}
}
child {
node[circle,draw] (e) {5}
}
child {
node[circle,draw] (f) {5}
}
}
child {
node[circle,draw] (b) {2}
}
;
\end{tikzpicture}
\end{document}

-
 Thanks a lot for your solution ;) – Chan Aug 15 '11 at 12:28

Rather than setting this all manually, you can use tikz-qtree to construct these kinds of trees very easily, and it will adjust the sibling distance automatically. (I've enlarged the default sibling distance slightly; but no other manual changes are required.)

\documentclass{article}
\usepackage{tikz-qtree}
\begin{document}
\tikzset{edge from parent/.style=
{draw, edge from parent path={(\tikzparentnode) -- (\tikzchildnode)}}}
\begin{tikzpicture}[every tree node/.style={draw,circle},sibling distance=.25cm]
\matrix{
\Tree
[.0
[.1 5 5 5 5  ]
[.2 ]
]
&
\Tree [.0
[.1 5 5 5 5 5 5 ]
[.2 6 6 ]
]
\\};
\end{tikzpicture}

\end{document}


-
 I'm amazed how powerful TiKZ is. Thanks a lot for your elegant solution. – Chan Aug 15 '11 at 17:00