0

Model image

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.

3
  • Welcome to TeX.SX! Please help us help you by making your example compilable.
    – TeXnician
    Commented Jan 3, 2018 at 10:37
  • @TeXnician You mean my code snippet has errors?
    – user151771
    Commented Jan 3, 2018 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
    Commented Jan 3, 2018 at 10:49

2 Answers 2

1

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}

enter image description here

0

Another solution to use the istgame package:

enter image description here

\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}

You must log in to answer this question.