# Horizontal Probability tree with tikz

I'm looking for a way to create a simple horizontal probability tree with tikz similar to this one:

I saw a few examples on texample.net, but no one shows me how to create the each paths horizontally.

## 2 Answers

One option using the powerful forest package:

\documentclass{article}
\usepackage{forest}

\begin{document}

\def\getfirst#1;#2\endget{#1}
\def\getsecond#1;#2\endget{#2}
\forestset{declare toks={elo}{}}
\begin{forest}
for tree={
grow=0,
calign=first,
s sep=2cm,
l=2cm,
},
before typesetting nodes={
for tree={content=\strut$#1$}
},
decision edge label/.style n args=3{
edge label/.expanded={
node[midway,auto=#1,anchor=#2,\forestoption{elo}]{\strut#3}
}
},
decision/.style={if n=1
{decision edge label={below}{north}{$#1$}}
{decision edge label={left}{east}{$#1$}}
},
delay={for descendants={
decision/.expanded/.wrap pgfmath arg={\getsecond#1\endget}{content},
content/.expanded/.wrap pgfmath arg={\getfirst#1\endget}{content},
}
},
[
[\bar{A};\frac{4}{9}
[\bar{A};\frac{3}{8}
[\bar{A};\frac{2}{7}
[\bar{A};\frac{1}{6}
[; ,no edge] [A;\frac{5}{9},elo={xshift=-3pt}]
] [A;\frac{5}{8},elo={xshift=-3pt}]
] [A;\frac{5}{7},elo={xshift=-3pt}]
] [A;\frac{5}{6},elo={xshift=-3pt}]
] [A;\frac{5}{5},elo={xshift=-3pt}]
]
\end{forest}

\end{document}


• Wow, nice solution. Thank you for sharing this! :) Feb 13 '14 at 18:54

Another forest solution. This one is for basic forest users while they try to understand Gonzalo's excellent answer.

\documentclass[border=2mm]{standalone}
\usepackage{forest}
\usepackage{amsmath}
\begin{document}
\tikzset{nicelabel/.style={midway, font=\scriptsize}}

\begin{forest}
[ \phantom{$\overline{A}$},for tree={calign=first, grow=0}
[$\overline{A}$, edge label={node[nicelabel, below]{$\frac{4}{9}$}}
[$\overline{A}$, edge label={node[nicelabel,below]{$\frac{3}{8}$}}
[$\overline{A}$, edge label={node[nicelabel,below]{$\frac{2}{7}$}}
[$\overline{A}$,  edge label={node[nicelabel,below]{$\frac{1}{6}$}}
[\phantom{$\overline{A}$}, no edge] [A, edge label={node[nicelabel,above]{$\frac{5}{5}$}}]]
[A, edge label={node[nicelabel,above]{$\frac{5}{6}$}}]]
[A, edge label={node[nicelabel,above]{$\frac{5}{7}$}}]]
[A, edge label={node[nicelabel,above]{$\frac{5}{8}$}}]]
[A, edge label={node[nicelabel,above]{$\frac{5}{9}$}}]]
\end{forest}
\end{document}