I have the following code:
\begin{tikzpicture}[grow=right, sloped]
\tikzstyle{level 1}=[level distance=1.3cm, sibling distance=1cm]
\tikzstyle{level 2}=[level distance=1.2cm, sibling distance=1cm]
\node[bag] {$S_i$}
child[grow=left] {
node[bag] {$S_{i+1}^{(1)}$}
child {
node[end, label=left:
{$S$}] {}
edge from parent[-latex]
node[above] {$W$}
}
child {
node[end, label=left:
{$S$}] {}
edge from parent[-latex]
node[above] {$B$}
}
child {
node[end, label=left:
{$S$}] {}
edge from parent[-latex]
node[above] {$B$}
}
edge from parent[-latex]
node[above] {$W$}
}
child[grow=right] {
node[bag] {$A$}
child {
node[bag] {$ \dots S_{i+1}^{(k_1)}$}
edge from parent[-latex]
node[above] {$w$}
}
child {
node[bag] {$S_{i+1}^{(2)}$}
child {
node[bag] {$S_{i+2}^{(2)(k_{\dots})}$}
edge from parent[-latex]
node[above] {u}
}
child {
node[bag] {$S_{i+2}^{(2)(2)}$}
edge from parent[-latex]
node[above] {u}
}
edge from parent[-latex]
node[above] {$w$}
}
child {
node[bag] {$S_{i+1}^{(1)}$}
child {
node[bag] {$S_{i+2}^{(1)(k_{\dots})}$}
edge from parent[-latex]
node[above] {u}
}
child {
node[bag] {$S_{i+2}^{(1)(2)}$}
edge from parent[-latex]
node[above] {u}
}
child {
node[bag] {$S_{i+2}^{(1)(1)}$}
edge from parent[-latex]
node[above] {u}
}
edge from parent[-latex]
node[above] {$w$}
}
edge from parent[-latex]
node[above] {$B$}
};
\end{tikzpicture}
Having in preamble
\tikzstyle{bag} = [text width=1.5em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]
My problem is that the branch on the right generates collisions and the tree does not expand automatically.
Basically speaking nodes do overlap. How can i avoid this???
Thanks
Best Answer
You just have to give appropriate values to
sibling distance
for the appropriate levels; in your example, the problematic levels are the second and the third:Perhaps you could also be interested in the
edge from parent path
option to control where the arrows will connect the nodes: