# How to add a numbered label to syntax tree?

\documentclass{article}
\usepackage{forest}

\begin{document}

\begin{forest} baseline, for tree={parent anchor=south, child anchor=north, align=center, l sep+=0em, s sep+=4em}
[T$'$
[T [{[past]}, name=tense2]]
[VP
[V$'$
[V$'$ [do, triangle, name=do2]]]]]
\draw[->] (tense2) to[out=south west, in=south] (do2);
\begin{forest} baseline, for tree={parent anchor=south, child anchor=north, align=center, l sep+=0em, s sep+=4em}
[T$'$
[T [{[pres]}, name=tense]]
[VP [do, triangle, name=do]]]
\draw[->] (tense) to[out=south, in=south] (do);
\end{forest}

\end{document}


Hi, I was wondering how I can put numbered labels to each trees like the picture I posted with this code. I am trying to put (1a) and (1b) to the left of each tree. Would somebody help me with this?

• Do you need the possibility for cross-referencing or do you just need plain text for the labels? – Gonzalo Medina Feb 6 '15 at 3:12
• Hi, I just need plain text for the labels for now. It would be better if I could cross-reference them. – mango tango Feb 6 '15 at 3:13
• Could it be OK to treat the whole thing as a float object or do you want it to be a static object? – Gonzalo Medina Feb 6 '15 at 3:18
• What does the 1 in (1a) and (1b) mean? Is it the number associated to a figure, are there other figures in your document and this is should be the one with number "1"? – Gonzalo Medina Feb 6 '15 at 3:20
• The numbers aren't part of the trees, right? They number the trees? So maybe you want these to be sub-figures or something like that? – cfr Feb 6 '15 at 3:22

Since trees in linguistics papers are treated as linguistic examples, it's typically not helpful to have them numbered independently of the system you use for numbering your example sentences. So the first place to begin should be with some of the various numbering systems for example numbering:

Then the issue is how to use these with trees created with forest or tikz-qtree. Usually this is as simply as just putting your forest environment inside an example environment. Since I use gb4e I've worked out an example with that, but similar things can be done with linguex or expex. To get side-by-side examples, I use the multicol package.

The advantage of this system is that you don't ever have to worry about the numbering of your examples if you move your trees to a different position within your paper.

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{forest}
\usepackage{multicol}
\usepackage{gb4e}
\begin{document}
\begin{exe}
\ex
\begin{multicols}{2}
\begin{xlist}
\ex
\begin{forest} baseline, for tree={parent anchor=south, child anchor=north, align=center, l sep+=0em, s sep+=4em}
[T$'$
[T [{[past]}, name=tense2]]
[VP
[V$'$
[V$'$ [do, triangle, name=do2]]]]]
\draw[->] (tense2) to[out=south west, in=south] (do2);
\end{forest}
\ex
\begin{forest} baseline, for tree={parent anchor=south, child anchor=north, align=center, l sep+=0em, s sep+=4em}
[T$'$
[T [{[pres]}, name=tense]]
[VP [do, triangle, name=do]]]
\draw[->] (tense) to[out=south, in=south] (do);
\end{forest}
\end{xlist}
\end{multicols}
\end{exe}
\end{document}


• It is very kind of you, Alan. I really appreciate this! :-) – mango tango Feb 11 '15 at 23:30

If you are only interested in placing the labels as plain text, standard TikZ \nodes can be used:

\documentclass[draft]{article}
\usepackage{forest}

\begin{document}

\begin{forest} baseline, for tree={parent anchor=south, child anchor=north, align=center, l sep+=0em, s sep+=4em}
[T$'$
[T [{[past]}, name=tense2]]
[VP
[V$'$
[V$'$ [do, triangle, name=do2]]]]]
\draw[->,overlay] (tense2) to[out=south west, in=south] (do2);
\node[anchor=north east] at (current bounding box.north west) {(1a)};
\begin{forest} baseline, for tree={parent anchor=south, child anchor=north, align=center, l sep+=0em, s sep+=4em}
[T$'$
[T [{[pres]}, name=tense]]
[VP [do, triangle, name=do]]]
\draw[->] (tense) to[out=south, in=south] (do);
\node[anchor=north east] at (current bounding box.north west) {(1b)};
\end{forest}

\end{document}


## Update

Adding the text width key to the label \nodes allows you to write text inside them (of course, you have to be careful about the width, otherwise you might obtain overfull \hboxes):

\documentclass{article}
\usepackage{forest}

\begin{document}

\begin{forest} baseline, for tree={parent anchor=south, child anchor=north, align=center, l sep+=0em, s sep+=4em}
[T$'$
[T [{[past]}, name=tense2]]
[VP
[V$'$
[V$'$ [do, triangle, name=do2]]]]]
\draw[->,overlay] (tense2) to[out=south west, in=south] (do2);
\node[anchor=north east,text width=3cm,inner xsep=0pt]
at (current bounding box.north west)
{(1a) And here we add some text that will span several lines};
\end{forest}\hfill
\begin{forest} baseline, for tree={parent anchor=south, child anchor=north, align=center, l sep+=0em, s sep+=4em}
[T$'$
[T [{[pres]}, name=tense]]
[VP [do, triangle, name=do]]]
\draw[->] (tense) to[out=south, in=south] (do);
\node[anchor=north east] at (current bounding box.north west) {(1b)};
\end{forest}

\end{document}


• Hi, Gonzalo. Can I ask you one more question? I'd like to put a long string of words (3 lines) at the same location with (1a). Would you show me how to do this? – mango tango Feb 7 '15 at 0:28
• @mangotango Please see my updated answer. – Gonzalo Medina Feb 7 '15 at 3:00
• @mangotango In the long run I don't think this is really the best way to integrate numbered trees into a linguistics paper, since they are never numbered independently of the example sentences in the paper. – Alan Munn Feb 11 '15 at 17:01