# How can I draw this (a tree diagram with notes on arrows) using forest?

Currently I can only write

\documentclass{article}
\usepackage{forest}

\begin{document}
\begin{forest}
for tree = {edge={->}}
[$a$
[$3a+1$]
[$\frac{a}{2}$]
]
\end{forest}
\end{document}


which produces a similar tree to the model, just without little words beside the arrows. Thanks.

• @TeXnician You mean my code snippet has errors? – Felix Fourcolor Jan 3 '18 at 10:46
• No, but we appreciate helping if we have a compilable code to copy and paste that runs, i.e. we do not have to guess documentclass, packages etc. (see also tex.meta.stackexchange.com/a/3225/124577) – TeXnician Jan 3 '18 at 10:49

Assign a name to each node, then use usual tikz commands with them. I did it like the following:

\documentclass{article}
\usepackage{forest}

\begin{document}
\begin{forest}
for tree = {edge={->}}
[$a$, name=root
[$3a+1$, name=left] {\path (root)-- node [rotate=65, yshift=3pt] {\tiny left} (left) ;}
[$\frac{a}{2}$, name=right] {\path (root)-- node [rotate=-65, yshift=3pt] {\tiny right} (right) ;}
]
\end{forest}
\end{document}


Another solution to use the istgame package:

\documentclass{standalone}
\usepackage{istgame}

\begin{document}
\begin{istgame}[->,sloped]
\xtdistance{20mm}{20mm}
\istroot(0)[null node]{$a$}
\istb{\mbox{odd}}[a]{3a+1}
\istb{\mbox{even}}[a]{\frac a2}
\endist
\end{istgame}
\end{document}