9

I have a problem when trying to label an edge that goes to a node that itself has children. Here is what I would like to do:

\begin{tikzpicture}
    \node {A}
    child { node {B} edge from parent [->] node [left] {\tiny 1} }
    child { node {C} edge from parent [->] node [right] {\tiny 2}
        child { node {D}  }
        child { node {E}  }
    }
    ;
\end{tikzpicture}

This does not work because, it would appear, Tikz thinks D and E are children of my label. I have tried adding braces in different spots to no avail.

So I have attempted a different strategy, given that my labelling needs are not very complicated, and tried this:

\begin{tikzpicture}[act1/.code={\node [above=5mm] {\tiny 1};},
                    act2/.code={\node [above=5mm] {\tiny 2};}]
    \node {A}
    child { node {B} edge from parent [act1,->] }
    child { node {C} edge from parent [act2,->]
        child { node {D}  }
        child { node {E}  }
    }
    ;
\end{tikzpicture}

act1 gives just about the right result, but as soon as I use act2, the code refuses to compile and gives me an error message I am unable to make sense of:

! Package pgf Error: No shape named is known.

(with two spaces between "named" and "is")

Any information about how to do this without resorting to a different package would be really appreciated!

1 Answer 1

9

The trick is simply to move edge from parent [->] node [right] {\tiny 2} after the two "children" of C.

\begin{tikzpicture}
    \node {A}
    child { node {B} edge from parent [->] node [left] {\tiny 1} }
    child { node {C} 
        child { node {D}  }
        child { node {E}  }
        edge from parent [->] node [right] {\tiny 2}
    }
    ;
\end{tikzpicture}

enter image description here

0

You must log in to answer this question.

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