I have drawn a tree in tikz with different styles for nodes (this simplified example has nodes with style a
or b
). The arrows from nodes to childs are always the same and I would like to apply different styles to the edge/arrow depending on the style of the parent node.
\begin{tikzpicture}[
a/.style={circle, draw=black, edge from parent/.style=myEdge1},
b/.style={rectangle, draw=red, edge from parent/.style=myEdge2},
myEdge1/.code={
\draw[-] \tikzparentnode -- \tikzchildnode;
}
myEdge2/.code={
% No edge or applying a different style
}
]
\node[a]{}
child {node[a] {}}
child {
node[b] {no arrows from this node}
child {node[a] {no arrow to this node}}
child {node[b] {no arrow to this node}}
}
child {node[a] {}}
;
\end{tikzpicture}
This is how it is supposed to look:
First of all, the code above does not work when edge from parent/.style=myEdge1
is defined within a style (a
or b
). It only works when I put it right behind the child, i.e. child[edge from parent/.style=myEdge1]
. Second (and this would probably solve the first issue), I would rather need edge to child
than edge from parent
since the style of the parent shall decide whether an arrow has to be drawn or not. But there is no such thing as edge to child
in the tikz documentation. Is there an easier solution than telling each child whether it should have an arrow from its parent or not such that tikz automatically adopts the edge style from the style of the parent node?