3

I have the following code:

\documentclass{article}

\usepackage{fontspec}

\usepackage[linguistics]{forest}

% specification for all trees, "default preamble" appends to existing specification.
% The version with apostrophe replaces it.
\forestset{default preamble'={
    for tree={align=center,parent anchor=south, child anchor=north,base=bottom},
    before drawing tree={
      sort by=y,
      for min={tree}{baseline}
    }
  }} 


\forestset{
  declare dimen={child anchor yshift}{0pt},
  adjust childrens child anchors/.style={
    if n children>=2{
      before packing={
        tempdima/.max={max_y}{children},
        for children={
          child anchor yshift=tempdima()-max_y()
        },
      }
    }{}
  },
  default preamble={
    for tree={
      edge path'={(!u.parent anchor)--([yshift=\forestoption{child anchor yshift}].child anchor)},
      adjust childrens child anchors
    }
  },
}



% The following code fixes the size of triangles for examples with translations. The specification
% ",delay=with translation" at the leaves is important to make this work.
% http://tex.stackexchange.com/questions/167978/smaller-roofs-for-forest/205311#205311
\forestset{
  with translation/.style={
    l sep=0,inner xsep=0,
    append translation/.expanded/.wrap pgfmath arg={\gettranslation{##1}}{content},
    content/.expanded/.wrap pgfmath arg={\gettext{##1}}{content},
  },  
  append translation/.style={
    if={strequal("#1","")}{}{
      append={[#1,no edge,inner xsep=0,inner ysep=0,outer ysep=0,
               l=\baselineskip + 0.2ex,
        ]}
    }
  } 
}

\def\gettext#1{\gettextA#1;;\endget}
\def\gettextA#1;#2;{\removesep#1;}
\def\gettranslation#1{\gettranslationA#1;;\endget}
\def\gettranslationA#1;#2;{\removesep#2;}
\def\removesep#1;#2\endget{#1}

\forestset{
sm edges/.style={for tree={parent anchor=south, child anchor=north,base=top}, % changed base=bottom
                                % to top since we have NP and AVM nodes and the NP has to start
                                % right away at the same hight as the AVM St. Mü. 18.10.2017
                 where n children=0{tier=word,delay=with translation}{} %,delay=with translation
                 },
}

    \usepackage{array}

\newcommand{\ms}[2][]{%
  \mbox{%
    \delimiterfactor=1000 \delimitershortfall=0pt
    \tabcolsep=0pt
    $\left[%
    \begin{tabular}{>{\upshape\scshape}l@{}>{\hspace*{5pt}\normalfont\itshape}l}
    \if\relax\detokenize{#1}\relax\else
    \multicolumn{2}{>{\normalfont\itshape}l}{#1}%
    \\ 
    \fi
    #2%
    \end{tabular}%
    \right]$%
  }%
  \vspace{1mm}%
}



    \begin{document}

\begin{forest}
sm edges, for tree={base=top}
[\ms{head & {1}\\
     comps & { }
     }
        [{{2} NP{[\textit{nom}]}}
                [er]]
        [\ms{
             head & {1}\\
             comps & { {2} }
             }
                [{3} NP{[\textit{dat}]}
                        [dem Mann, roof]]
                [\ms{
                                                                                   head & {1}\\
                                                                                   comps & { {2}, {3} }
                                                                                    }
                        [{4} NP{[\textit{acc}]}
                                [das Buch, roof]]
                        [\ms{
                                                                                   head & {1} \ms[verb]{
                                                                                                  vform & fin
                                                                                                  }\\
                                                                                   comps & { {2}, {3}, {4} }
                                                                                    }
                                [gibt]]]]]  
\end{forest}


\end{document}

It produces the following tree:

enter image description here

The NPs to the left are aligned to the middle of the AVMs. In sm edges I defined base=top and it is different from base=bottom, but the result is more like something one would expect from base=center. Is this a bug in forest or is there another way to align the text at the top?

  • So you want the NP labels to be higher, and align with the top of the AVMs? (Not everyone will know what an AVM is, BTW). – Alan Munn Oct 18 '17 at 13:24
  • Ehm sorry, yes, Attribute Value Matrice. Yes, and the NP shoul align with the top of it. As you described it. – Stefan Müller Oct 18 '17 at 13:31
  • Am I missing something? Doesn't most of your code implement an alignment you explicitly don't desire? – cfr Mar 23 '18 at 4:16
3

Simply try anchor=north

for tree={anchor=north, parent anchor=south, child anchor=north}

p.s. have done a master thesis on HPSG :)

enter image description here

  • This answer obscures the fact that most of the OP's code is designed ti implement a style the OP doesn't desire. The solution primarily lies in removing that code. Simply undoing its effects is not the simplest or the most robust solution by a long way. – cfr Mar 23 '18 at 4:15
2

Assuming you want something like this:

output (target)

Much of the code you have is at best unnecessary and at worst counter-productive. In particular, all the default preamble stuff can be axed. The translation apparatus is also expendable, though you can leave this in place if you require it in other trees (the output for this tree will be unchanged).

This leaves you with a simpler problem which can be solved by setting anchor=parent for the tree.

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

\forestset{
  sm edges/.style={%
    where n children=0{tier=word}{},
  },
}

\usepackage{array}

\newcommand{\ms}[2][]{%
  \mbox{%
    \delimiterfactor=1000 \delimitershortfall=0pt
    \tabcolsep=0pt
    $\left[%
    \begin{tabular}{>{\upshape\scshape}l@{}>{\hspace*{5pt}\normalfont\itshape}l}
      \if\relax\detokenize{#1}\relax\else
      \multicolumn{2}{>{\normalfont\itshape}l}{#1}%
      \\ 
      \fi
      #2%
    \end{tabular}%
    \right]$%
  }%
  \vspace{1mm}%
}



\begin{document}

  \begin{forest}
    sm edges, 
    for tree={anchor=parent},
    [\ms{head & {1}\\
      comps & { }
    }
    [{{2} NP{[\textit{nom}]}}
    [er]]
    [\ms{
      head & {1}\\
      comps & { {2} }
    }
    [{3} NP{[\textit{dat}]}
    [dem Mann, roof]]
    [\ms{
      head & {1}\\
      comps & { {2}, {3} }
    }
    [{4} NP{[\textit{acc}]}
    [das Buch, roof]]
    [\ms{
      head & {1} \ms[verb]{
        vform & fin
      }\\
      comps & { {2}, {3}, {4} }
    }
    [gibt]]]]]  
  \end{forest}

\end{document}
  • Hm, Saso did the default stuff and I forgot what it does. I am afraid of any side effects when I remove it. – Stefan Müller Mar 23 '18 at 10:20
  • @StefanMüller Please yourself. Not much I can say about that really. But applying settings to all trees if you only want them for some trees and then undoing them by adding more stuff for the others is asking for trouble. – cfr Mar 23 '18 at 22:14
  • I added the anchor=north to the default. – Stefan Müller Mar 24 '18 at 10:25
  • @StefanMüller As I say, it's your funeral: it is up to you what code you use. – cfr Mar 24 '18 at 19:12

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.