2

Question: I am stuck in drawing of tree. Actual problem is i wish to draw two more nodes(having names H and I) exactly below to node F. but i couldn't problem is of overlapping of nodes.

MWE:

\documentclass[10pt]{article}
\usepackage{tikz}

\begin{document}
    \begin{center}
        \begin{tikzpicture}
        \node [circle,draw]{A} [level distance=10mm,sibling distance=25mm]
        child { node [circle,draw]{B} [level distance=10mm ,sibling distance=15mm]
            child {node [circle,draw] {D}
                child[missing]
                child {node [circle,draw]{G}}}
            child {node [circle,draw]{F}}
        }
        child {node [circle,draw] {C} [level distance=10mm ,sibling distance=15mm]
            child {node [circle,draw] {E}
                child[missing]                  
                child {node [circle, draw] {J}} 
            }
            child {node [circle,draw] {F}
                child[missing]                  
                child {node [circle, draw] {K}} 
            }
                };
        \end{tikzpicture}
    \end{center}    
\end{document}
2

You could move the D node a bit to the left to make room, with e.g.

node [circle,draw,xshift=-5mm] {D}

and perhaps also reduce the distance between H and I the same way you did earlier, with

node [circle,draw]{F} [sibling distance=7mm] child {node[circle,draw]{H}} child {node[circle,draw]{I}}

If you don't need to emphasize the missing children, then no shifting is needed, but I don't know if that is OK. Anyways, see the second example in the code below for that. In the first two examples below I used \path[every node/.style={circle,draw}] followed by the tree, then you don't have to specify [circle, draw] for every single node.

Another, more automated, method for drawing trees is the forest package. I added an example of that as well.

\documentclass{article}
\usepackage{forest} % loads tikz
\begin{document}
\begin{center}
Small adjustments:

\begin{tikzpicture}
    \path[every node/.style={circle,draw}]
         node {A} [level distance=10mm,sibling distance=25mm]
        child { node {B} [level distance=10mm ,sibling distance=15mm]
            child {node [xshift=-5mm] {D}
                child[missing]
                child {node {G}}}
            child {node {F} [sibling distance=7mm]
                child {node{H}}
                child {node{I}}}
        }
        child {node  {C} [level distance=10mm ,sibling distance=15mm]
            child {node  {E}
                child[missing]                  
                child {node {J}} 
            }
            child {node  {F}
                child[missing]                  
                child {node {K}} 
            }
                };
\end{tikzpicture}

Larger adjustments:

\begin{tikzpicture}
  \path[every node/.style={circle,draw}]
     node {A} [level distance=10mm,sibling distance=25mm]
        child { node {B} [sibling distance=13mm]
            child {node {D}
                child {node {G}}}
            child {node {F} [sibling distance=10mm]
                child {node{H}}
                child {node{I}}}
        }
        child {node  {C} [sibling distance=10mm]
            child {node  {E}
                child {node {J}} 
            }
            child {node  {F}             
                child {node {K}} 
            }
                };
\end{tikzpicture}

Forest:

\begin{forest}
for tree={draw,circle}
[A 
 [B
  [D [G] ]
  [F [H] [I] ]
 ]
 [C
  [E [J]]
  [F [K]]
 ]
]
\end{forest}
\end{center}    
\end{document}

enter image description here

  • Great work done by you. Millions thanks. – Maths4Sandy Sep 28 '19 at 15:05
  • Might want to add a minimum size to avoid some circles coming out smaller than others? – cfr Oct 5 '19 at 2:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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