# Aligning several forest trees in centered way

I want to align three trees in the way shown in the following figure:

What I have now is the following code:

\documentclass{minimal}

\usepackage{forest}

\forestset{
tag/.style={for tree={parent anchor=south, child anchor=north,align=center,base=top},where
n children=0{}{}}
}

\begin{document}

\hfill
\begin{forest}
tag
[NP
[John]]
\end{forest}
\hfill
\begin{forest}
tag
[S
[NP$\downarrow$]
[VP
[V
[laughs]]]]
\end{forest}
\hfill
\begin{forest}
tag
[VP
[always]]
[VP*]]
\end{forest}
\hfill\mbox{}

\end{document}


I know of the baseline attribute, but this would not do real centering. Before using forest I just used tables and this got the alignment right automatically.

I can think of two ways of accompishing this without external help. Both use the fact that tikz/pgf keeps track of the picture's bounds in a special node called current bounding box.

1. Use tikz's baseline option, which must be given as an argument to tikzpicture environment. This can be achieved by changing forest's option begin draw (at any node, but probably in the preamble)

2. Use pgf's \pgfsetbaselinepointlater, which can be injected from forest' by using forest's tikz option (again, at any node, but probably in the preamble).

In your example, use this definition of tag style (the first way is active, the second way is commented out):

\forestset{tag/.style={
for tree={parent anchor=south, child anchor=north,align=center,base=top},where n children=0{}{},
begin draw/.code={\begin{tikzpicture}[baseline=(current bounding box.center)]},
%tikz+={\pgfsetbaselinepointlater{\pgfpointanchor{current bounding box}{center}}},
}}


Seek help from adjustbox package with valign=m or c (t for top, b for bottom) does the objectives.

Code

\documentclass{minimal}
\usepackage{forest}

\forestset{
tag/.style={for tree={parent anchor=south, child anchor=north, align=center, base=top}, where  n children=0{}{}}
}

\begin{document}

\hfill
\begin{forest}
tag
[NP
[John]]
\end{forest}}
\hfill
\begin{forest}
tag
[S
[NP$\downarrow$]
[VP
[V
[laughs]]]]
\end{forest}}
\hfill
\begin{forest}
tag
[VP

• Thanks! When I load it, I get an error telling me that \clipbox is already defined. Hm. – Stefan Müller Oct 12 '14 at 9:28
• The adjustbox package does use clipbox according to its manual located in the INTRODUCTION. So your code must have other packages cause such clash. Probably, disable those packages first and find out which one is causing this error. Further, I checked the version of adjustbox package in the compiled log file: adjustbox 2012/05/21 v1.0 – Jesse Oct 12 '14 at 10:25
• Thanks! It was pstricks and the link to the trick was very helpful indeed! – Stefan Müller Oct 12 '14 at 10:35