Consider the tree below. Is there an easy way to label every left edge q, every right edge p, every left node f and every right node r, without doing it manually for every level?
Second question: Is there a nice way to generalize this Bernoulli process tree example for n-levels?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\pagestyle{empty}
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=6cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=3cm]
\tikzstyle{level 3}=[level distance=3.5cm, sibling distance=2cm]
\tikzstyle{bag} = [text centered,circle,draw,inner sep=0.3em]
\tikzstyle{head} = [inner sep=0pt]
\begin{tikzpicture} %
\node[head] {} %
child { %
node[bag] {} %
child{ %
node[bag]{}
child { %
node[bag, label=below: %
{$a$}] {} %
} %
child { %
node[bag, label=below: %
{$b$}] {} %
} %
}%
child{ %
node[bag]{}
child { %
node[bag, label=below: %
{$c$}] {} %
} %
child { %
node[bag, label=below: %
{$d$}] {} %
} %
}%
}
child { %
node[bag] {} %
child{ %
node[bag]{}
child { %
node[bag, label=below: %
{$e$}] {} %
} %
child { %
node[bag, label=below: %
{$f$}] {} %
} %
}%
child{ %
node[bag]{}
child { %
node[bag, label=below: %
{$g$}] {} %
} %
child { %
node[bag, label=below: %
{$h$}] {} %
} %
}%
}; % %
\end{tikzpicture}
\end{document}
Best Answer
I work on something like that but I need to work on this code (no time actually) You can look at
\pgfqkeys{/berntree}
to see all the options. The limit is 5 but it would be nice to use a recurrent method to build this tree ! I made some modifications now you can modify the styles :node success style
annode miss style
. To add some labels at the end of each branch , you can use the last nodes ( it's not very easy) and for the label on the edges you can useedge style
. The code is not very fine because the arrows are inside some nodes and it would be better to give the same size for each nodes. Version 4 :edge style/.style = {->,>=latex',shorten <= 6pt}
for the edge's problem and see the final loops for the labels. I fixed the size's nodes