# Forest trees on the same line

I need to put two trees (package forest) side by side, but I haven't find any info on the package documentation.

\begin{forest}
[P1
[SN
[N[Mary]]]

[VP
[V[loves]]
[N[Luke]]
]]

\end{forest}

\begin{forest}
[P2
[NP
[Pro[This]]]
[VP
[V[is]]
[NP
[Det[a]]
[N[xx]]
]]]

\end{forest}

• You can put every forest environment in a separate minipage environment. Nov 23 '13 at 16:03
• Don't leave an empty line between the two forest environment: a blank line makes a paragraph end. To TeX's eyes, a forest is just a big letter. Nov 23 '13 at 16:13
• Note that you cannot leave empty lines within a forest environment. You code in its current form will cause errors during compilation, even if with the correct preamble. Nov 29 '13 at 19:08
• You can find info and documentation for all packages on CTAN: ctan.org/pkg/forest Nov 29 '13 at 19:35

No need of phantoms: use adjustbox and its features for moving boxes around. A tree made by forest has its reference point at the bottom, we can align at the top with valign=t.

\documentclass{article}

\begin{document}
\begin{forest}
[P1
[SN
[N[Mary]]]
[VP
[V[loves]]
[N[Luke]]
]]
\end{forest}
\begin{forest}
[P2
[NP
[Pro[This]]]
[VP
[V[is]]
[NP
[Det[a]]
[N[xx]]
]]]
\end{forest}

\end{document}


• Why not just use the baseline option (i.e., \begin{forest} baseline)? Then you don't have to use adjustbox at all. Oct 6 '14 at 7:16
• @AdamLiter That's covered by Qrrbrbirlbel Oct 6 '14 at 7:31
• Ah, fair point. Didn't scroll that far down. :) Oct 6 '14 at 7:35

It's a little bit tricky. You draw both trees as branches from a phantom parent. This idea has been stolen from several examples in forest documentation.

\documentclass[tikz,border=2mm]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
[, phantom, s sep = 1cm
[P1
[SN [N  [Mary]]]
[VP [V  [loves]]
[N  [Luke]]]
]
[P2
[NP [Pro [This]]]
[VP [V [is]]
[NP [Det [a]]
[N  [xx]]]]
]
]
\end{forest}
\end{document}


You have two errors in your code that exclude the possibility to have both trees on the same horizontal line:

1. You have an empty line between the forest environments which TeX interprets as a new paragraph. Remove that empty line or insert a %.
2. Your forest environments has empty lines in it. This prevents TeX from compiling your code at all as it breaks the forest parser. The same rule as for above is valid.

You now have both forest trees on the same horizontal line. As TeX sees the trees (the underlying TikZ pictures) as two big box which have their baseline at the bottom the roots of the trees are not vertically aligned.

You can change this with the baseline option (a forest option here, there also exist a TikZ baseline option). At any node you use the baseline option, the baseline of the whole tree is set. In this way, you can give the baseline option to the VP node in the first tree and the Det node in the second tree to vertically align the pictures at these node. Is the option given as an option to the forest environment, the option is applied to the root node.

If you want both trees in one picture (to make it easy to draw between them), the phantom option might be helpful. You may need to include a few phantom levels to align the sub-trees at different levels as in the example before.

## Code

\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest} baseline
[P1
[SN
[N[Mary]]]
[VP
[V[loves]]
[N[Luke]]
]]
\end{forest}\hspace{1cm}
\begin{forest} baseline
[P2
[NP
[Pro[This]]]
[VP
[V[is]]
[NP
[Det[a]]
[N[xx]]
]]]
\end{forest}
\end{document}


Similar to Ignasi's idea, you can draw a "phantom" edge that makes the shorter tree to have the same levels as the taller tree. And this allows for two forest environments.

# Code

\documentclass{article}
\usepackage{forest}

\begin{document}
\begin{forest}
[P1
[SN
[N[Mary]]]
[VP
[V[loves]]
[N[Luke
[,no edge] % phantom edge to increase tree level
]]
]]
\end{forest}
\begin{forest}
[P2
[NP
[Pro[This]]]
[VP
[V[is]]
[NP
[Det[a]]
[N[xx]]
]]]
\end{forest}
\end{document}