[Tex/LaTex] How to control spacing in a TikZ tree

tikz-pgftrees

I want to draw a tree and I don't know how to enforce the spacing between them. Some are overlapping.

This is my code:

\begin{tikzpicture}
\tikzstyle{every node}=[circle,draw]
\node {A}
child { node {B} 
child { node {E} }
child { node {F} child { node {K} } child { node {L} } child { node {M}}}
child { node {G} }}
child { node {C} 
child {node {H}}}
child { node {D} child {node {I}} child {node {J} child {node {N}} child {node {O}}}};
\end{tikzpicture}

The nodes G and H are overlapping.

I've tried using the parameter node distance but it doesn't work.

Best Answer

Refer to Section 18.4 Specifying Options for Trees and Children of the pgfmanual. Using sibling distance, you can solve the problem (use the values that best suit your needs):

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[every node/.style={circle,draw},level 1/.style={sibling distance=30mm},level 2/.style={sibling distance=10mm}
]
\node {A}
child { node {B} 
child { node {E} }
child { node {F} child { node {K} } child { node {L} } child { node {M}}}
child { node {G} }}
child { node {C} 
child {node {H}}}
child { node {D} child {node {I}} child {node {J} child {node {N}} child {node {O}}}}
;
\end{tikzpicture}

\end{document}

Related Question