1

I am wondering how to add arrows to the Forest package syntax tree. I am hoping I don't have to use the Tkiz package to manually draw things. I hope to draw something like this:

enter image description here

My attempt so far:

\begin{forest}
  [
    E [E[T[T [F [digit]]  ][*][F [digit] ]]]
    [+]
    [T [F [digit]]]
  ]
\end{forest}

enter image description here

5
  • Maybe use the decorations library to add a decoration to the edge path? Just an idea; not sure if it would work.
    – Alan Munn
    Sep 30, 2021 at 23:56
  • The forest manual show a few examples of trees with some arrow.
    – Fran
    Oct 1, 2021 at 0:32
  • give names to nodes and after that draw arrows manually where needed?
    – Zarko
    Oct 1, 2021 at 0:42
  • @Fran do you know where I can find the docs?
    – Node.JS
    Oct 1, 2021 at 0:46
  • @Node.JS Just run texdoc forest i.e., run the program texdoc that you have and search the term "forest. In Case that you have not a LaTeX distro installed in the computer (i.e, you are using Overleaf) , there also a texdoc online. Alternatively, you can also search the forest package in CTAN site, and then you will see here a link to the manual.
    – Fran
    Oct 1, 2021 at 8:48

1 Answer 1

2

I got it working using the \draw command.

\begin{forest}
  [
    E, name=11
    [E,name=7 [T, name=6 [T,name=3 [F,name=2 [digit, name=1]]  ][*][F, name=5 [digit, name=4]  ]]]
    [+]
    [T, name=10 [F, name=9  [digit, name=8 ]]]
  ]
  \draw[->,dotted] (1) to[out=west,in=south west] (2);
  \draw[->,dotted] (2) to[out=north west,in=south west] (3);
  \draw[->,dotted] (3) to[out=north west,in=west] (6);
  \draw[->,dotted] (4) to[out=east,in=south east] (5);
  \draw[->,dotted] (5) to[out=north east,in=east] (6);
  \draw[->,dotted] (6) to[out=north west,in=south west] (7);
  \draw[->,dotted] (8) to[out=east,in=south east] (9);
  \draw[->,dotted] (9) to[out=north east,in=south east] (10);
  \draw[->,dotted] (7) to[out=north west,in=west] (11);
  \draw[->,dotted] (10) to[out=north east,in=east] (11);
\end{forest}

enter image description here

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.