# Making a probability tree using tikzpicture / forest

I want to create a probability tree using either tikzpicture or forest. I have experimented a little bit with both, but I'm running into some trouble with both of the programs.

First, I have my code for tikzpicture that I want to create:

![\begin{tikzpicture}$grow=right, sloped$
\node$bag$ {(1, 1)}
child {
node$bag$ {($\frac{1}{2}$, $\frac{1}{2}$)}
child {
node {($\frac{1}{4}$, $\frac{1}{4}$)}
edge from parent
node$above$ {$T$}
node$below$  {$\frac{1}{2}$}
}
child {
node {(1, 1)}
edge from parent
node$above$ {$H$}
node$below$  {$\frac{1}{2}$}
}
edge from parent
node$above$ {$T$}
node$below$  {$\frac{1}{2}$}
}
child {
node$bag$ {(2, 2)}
child {
node {(1, 1)}
edge from parent
node$above$ {$T$}
node$below$  {$\frac{1}{2}$}
}
child {
node {(4, 4)}
edge from parent
node$above$ {$H$}
node$below$  {$\frac{1}{2}$}
}
edge from parent
node$above$ {$H$}
node$below$  {$\frac{1}{2}$}
};
\end{tikzpicture}][1]


Next, I have my forest code:

\begin{forest}
for tree={grow=0,l=3cm,anchor=west,child anchor=west}
[{$(1, 1)$}
[{$(\frac{1}{2}, \frac{1}{2})$}
[{$(\frac{1}{4}, \frac{1}{4})$}]
[{$(1,1)$}]
]
[{$(2, 2)$}
[{$(1,1)$}]
[{$(4,4)$}]
]
]
\end{forest}


I like the tikzpicture style and spacing very much, except I would love to be able to have labels along the bottom that say "$t=0$", "$t=1$", "$t=2$", etc. that are in a single horizontal line? Is there a way to do this in tikzpicture? I want the labels like in the answer to this question.

Regarding the forest code, I think that the diagram is too condensed and squished together. Is there a way to make it more spread out, like the tikzpicture? Also, is there a method to create labels "$t=0$", "$t=1$", "$t=2$", etc. as above?

The above graph is my tikzpicture and the below is my forest.

• Can you please edit your question and combine your code fragments into a single compilable document? This will make it easier for others to play with the code. – Alan Munn Jul 29 '14 at 23:00
• The question you linked to with the labels you want has an answer which uses forest so you can adapt that to do the labelling. Try fit=rectangle or fit=band for a less compact tree. (Page 29.) – cfr Jul 29 '14 at 23:02

One way to space out the tree in forest is to increase the minimum distance between the siblings. As mentioned above, fit can also be used to adjust the spread.

\documentclass{standalone}
\usepackage{forest}
\usetikzlibrary{positioning}

\begin{document}

\begin{forest}
for tree={grow=0,l=3cm,anchor=west,child anchor=west, s sep+=10pt}
[{$(1, 1)$}, name=t0
[{$(\frac{1}{2}, \frac{1}{2})$}
[{$(\frac{1}{4}, \frac{1}{4})$}, name=bot]
[{$(1,1)$}]
]
[{$(2, 2)$}, name=t1
[{$(1,1)$}]
[{$(4,4)$}, name=t2]
]
]
\coordinate [below=of bot] (coord);
\foreach \i in {0,...,2}
\node at (coord -| t\i) {$t=\i$};
\end{forest}

\end{document}