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.

  • Welcome to TeX.SX! Please help us help you by making your example compilable. – TeXnician Jan 3 '18 at 10:37
  • @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
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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.