5

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

enter image description here

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
        [ADV
                [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.

3

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}}},
  }}
3

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

enter image description here

Code

\documentclass{minimal}   
\usepackage[export]{adjustbox}
\usepackage{forest}

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


\begin{document}


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

\end{document}
  • 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
  • Please check this: tex.stackexchange.com/a/86032/34618. egreg's second alternative could be one possible solution. If not, then a new question is indeed justified. – Jesse Oct 12 '14 at 10:28
  • Thanks! It was pstricks and the link to the trick was very helpful indeed! – Stefan Müller Oct 12 '14 at 10:35
  • You are welcome, I leaned from your question too. Thanks. – Jesse Oct 12 '14 at 10:44

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.