I'm trying to replicate the following tree in LaTeX:
I'm having problems, because (1) I never drew a tree diagram with 90º degrees branches, like this, and (2) I never drew a tree diagram together with numbered examples.
I tried using tikz-qtree
and forest
, but I didn't get anywhere.
So I tried using tabbing
environment to solve the numbered exemples problem, but now I don't know what package to use to draw the lines.
This is my current (and horribly written) code:
\documentclass[]{article}
\begin{document}
\begin{tabbing}
\hspace{0em} $(20)$ \= \hspace{2em} $n$ \= \hspace{1em} $s/(n)[n]$ \=
\hspace{1em} $n/[s]$ \= \hspace{1em} $n$ \= \hspace{1em} $s/(n)$ \=
\hspace{1em} $s/(n)//(s/(n))$ \= \hspace{1em} $s/(n)//(s/(n))[n]$ \=
\hspace{1em} $n$ \= \hspace{1em} $n/(n)$\\~\\
\hspace{0em} $(21)$\= \hspace{37.5em} $n$\\~\\
\hspace{0em} $(22)$\= \hspace{17.5em} $s/(n)$\\~\\
\hspace{0em} $(23)$\= \hspace{30em} $s/(n)$\\~\\
\hspace{0em} $(24)$\= \hspace{20,5em} $s$\\~\\
\hspace{0em} $(25)$\= \hspace{14em} $n$\\~\\
\hspace{0em} $(26)$\= \hspace{6em} $s$\\
\end{tabbing}
\end{document}
Resulting in:
Can anyone give me some help on how to resolve this nightmare I'm having to replicate the tree diagram of the first image?
Best Answer
Here's a version using
forest
.Explanation of the code
edges
library fromforest
to make easy square branches.grow=north
to make the tree upside down.tier
key allows all the terminal nodes of the tree to be aligned at the top of the tree. It is also used to separate line (21) from (22) since in the tree they are at the same level of embedding, but in numbering they are not. By aligning the nodes in the tree with the nodes in the numbering we achieve the desired result.enumerate=...
key and counting down from there. Again, thetier
key is used keep the alignment correct.