I am using the 'forest' package in LaTeX in order to create decision trees with multiple decisions. I've got it mostly how I want it, except for two things:
- I'd like the circles at the leaves of the tree to be triangles.
- I'd like labels to be centred on the lines and not overlapping with the rectangles or circles.
A simple example (using Beamer):
\documentclass{beamer}
\usepackage{beamerstyle}
\usepackage{tikz}
\usetikzlibrary{trees,shapes,snakes}
\usepackage{forest}
\tikzset{
decision/.style={rectangle, minimum height=10pt, minimum width=10pt, draw=black, fill=black!30!white, thick, inner sep=0pt},
chance/.style={circle, minimum width=10pt, draw=black, fill=black!30!white, thick, inner sep=0pt},
}
\begin{document}
\begin{frame}[fragile]
\scalebox{0.85}{
\begin{forest}
my label/.style={
edge label={node[auto,sloped,pos=.75,anchor=south]{#1}}
},
for tree={
grow=0,
child anchor=west,
parent anchor=east,
line width=0.2pt,
inner sep=1mm,
edge={thick, draw=blue},
l sep+=30mm,
s sep+=5mm,
if n children=0{
before typesetting nodes={
label/.wrap pgfmath arg={right:#1}{content()},
content={},
chance,
},
}{},
edge path={
\noexpand\path[\forestoption{edge}]
(!u.parent anchor) -- ([xshift=-1.6cm].child anchor) --
(.child anchor)\forestoption{edge label};
},
}
[, decision
[,decision,my label=Route 1
[,chance,my label=Fast
[-900, my label=Accident]
[100, my label=No Accident]
]
[,chance,my label=Slow
[-700, my label=Accident]
[50, my label=No Accident]
]
]
[,decision,my label=Route 2
[,chance,my label=Fast
[-600, my label=Accident]
[80, my label=No Accident]
]
[,chance,my label=Slow
[-500, my label=Accident]
[70, my label=No Accident]
]
]
]
\end{forest}
}
\end{frame}
\end{document}

Edit: Thanks to @AlanMunn for help with the triangles. I've flipped them around. Also got rid of the angled lines so that the labels look better. I prefer angled lines but can't get it looking good.
\documentclass{beamer}
%\usepackage{beamerstyle}
\usepackage{tikz}
\usetikzlibrary{trees,shapes,snakes}
\usepackage{forest}
\tikzset{
decision/.style={rectangle, minimum height=10pt, minimum width=10pt, draw=black, fill=black!30!white, thick, inner sep=0pt},
chance/.style={circle, minimum width=10pt, draw=black, fill=black!30!white, thick, inner sep=0pt},
leaf-chance/.style={isosceles triangle, minimum width=10pt, draw=black, thick, fill=white, inner sep=0pt, shape border rotate=180, outer sep=-\pgflinewidth}
}
\begin{document}
\begin{frame}[fragile]
\scalebox{0.85}{
\begin{forest}
my label/.style={
edge label={node[auto, sloped,pos=.75,anchor=south]{#1}}
},
for tree={
grow=0,
child anchor=west,
anchor=west,
text ragged,
inner sep=1mm,
edge={thick, draw=blue},
l sep+=30mm,
s sep+=5mm,
if n children=0{
before typesetting nodes={
label/.wrap pgfmath arg={right:#1}{content()},
content={},
leaf-chance,
},
}{},
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) |- (.child anchor)\forestoption{edge label};
% alternatively, with angled lines
%\noexpand\path[\forestoption{edge}]
% (!u.parent anchor) -- ([xshift=-2.6cm].child anchor) --
% (.child anchor)\forestoption{edge label};
},
}
[, decision
[,decision,my label=Route 1
[,chance,my label=Fast
[-900, my label=Accident]
[100, my label=No Accident]
]
[,chance,my label=Slow
[-700, my label=Accident]
[50, my label=No Accident]
]
]
[,decision,my label=Route 2
[,chance,my label=Fast
[-600, my label=Accident]
[80, my label=No Accident]
]
[,chance,my label=Slow
[-500, my label=Accident]
[70, my label=No Accident]
]
]
]
\end{forest}
}
\end{frame}
\end{document}




http://tex.stackexchange.com/questions/34442/decision-tree-with-tikz?rq=1
http://tex.stackexchange.com/questions/240760/adding-text-above-a-node-in-tikzpicture-tree-diagram?lq=1
– fraserbc Jun 19 '15 at 21:24BTW, I was going to answer my question rather than edit it, with a hat-tip to AlanMunn plus my own edits, but the site showed me a warning asking if I really wanted to do that, so I didn't. Wasn't sure of the normal protocol.
– fraserbc Jun 19 '15 at 21:31