[Tex/LaTex] Draw a tree with tikz

tikz-pgftikz-treestrees

I have some problems I am not able to fix with this tree in TikZ:

  1. how can I avoid the empty space near the root?
  2. how can I write a text on branches? I used edge from parent but does not work how I expect.

This is the code I'm using:

 \begin{tikzpicture}
 [ level 1/.style={sibling distance=6em},
   level 2/.style={sibling distance=4em}, level distance=1cm,
   level 3/.style={sibling distance=2em}, level distance=1cm] 
\node (root) {}  [fill]  circle (1.5pt)
   child {  [fill]  circle (1.5pt) 
    child {  [fill]  circle (1.5pt)
        child {}
        child {}
    }
    child {
    }
}
child {  [fill]  circle (1.5pt) 
        child {}
        child {}
}
;
\node at (root)[right]{I};
\node at (root-1)[left] {II};
\node at (root-2)[right] {II};

\end{tikzpicture}    

And this is what I get:
Fix this tree

Best Answer

In order to avoid the empty space at the root, you want to make the root a coordinate, rather than a node, since nodes have some minimal dimension, whereas a coordinate does not.

As for text on the branches, you can, in fact, do it with edge from parent. It's hard to say where you're going wrong, since there isn't an example in your MWE, but the MWE below includes an example where it's working.

You might want to look at page 326 of the TikZ and PGF documentation.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[
    level 1/.style={sibling distance=6em},
    level 2/.style={sibling distance=4em}, level distance=1cm,
    level 3/.style={sibling distance=2em}, level distance=1cm
    ] 
\coordinate (root) {}  [fill]  circle (1.5pt)
    child {  [fill]  circle (1.5pt)
        child {  [fill]  circle (1.5pt)
            child {}
            child {}
            edge from parent
                node[left] {a}
        }
        child {
        }
    }
    child {  [fill]  circle (1.5pt) 
        child {}
        child {}
    }
    ;
\node at (root)[right]{I};
\node at (root-1)[left] {II};
\node at (root-2)[right] {II};
\end{tikzpicture} 
\end{document}

enter image description here

Related Question