6

I use forest to typeset trees. This works really great, but somehow AVMs are treated differently from normal text. I guess it has to do with the baseline of a tabular environment in the AVM. I tried to set the t option in tabular, but this does not work. So how can I get an alignment between the AVMs and other nodes in the tree in the following way:

enter image description here

This is the code:

\documentclass{article}
\usepackage{forest}

\forestset{
sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=top},
                 where n children=0{tier=word,delay=with translation}{}
                 }}

\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={append={[#1,no edge,l=0,inner xsep=0,inner ysep=0,outer ysep=0,before computing xy={l-=2pt}]}}
}

\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}


\usepackage{array}
\setlength{\extrarowheight}{1pt}

\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}%
}

\def\ibox#1{\mbox{}\setbox2=\hbox{$\scriptstyle #1$}\lower.2ex\vbox{\hrule
        \hbox{\vrule\kern1.25pt 
        \vbox{\kern1.25pt\box2\kern1.25pt}\kern1.25pt\vrule}\hrule}}

\newcommand{\liste}[1]{%
\mbox{%
$%
\left\langle\begin{tabular}{@{}>{\upshape\scshape}l@{}}#1\end{tabular}\right\rangle%
$%
}%
}


\begin{document}


\begin{forest}
sn edges
[\ms{head & \ibox{1}\\
     subcat & \liste{ }
     }
        [{\ibox{2} NP{[\textit{nom}]}}
                [er;he]]
        [\ms{
             head & \ibox{1}\\
             subcat & \liste{ \ibox{2} }
             }
                [\ibox{3} NP{[\textit{dat}]}
                        [dem Mann;the man, triangle]]
                [\ms{
                                                                                   head & \ibox{1}\\
                                                                                   subcat & \liste{ \ibox{2}, \ibox{3} }
                                                                                    }
                        [\ibox{4} NP{[\textit{acc}]}
                                [das Buch;the book, triangle]]
                        [\ms{
                                                                                   head & \ibox{1} \ms[verb]{
                                                                                                  vform & fin
                                                                                                  }\\
                                                                                   subcat & \liste{ \ibox{2}, \ibox{3}, \ibox{4} }
                                                                                    }
                                [gibt;gives]]]]]    
\end{forest}

\end{document}
  • 1
    What are AVM's? – Ulrike Fischer Mar 1 '16 at 9:42
  • Attribute value matrices. Sorry. – Stefan Müller Mar 1 '16 at 11:32
  • The nodes are already tabulars if you use align. Don't put more tabulars inside. Redefine align to whatever tabular specification you need. Also, note that you are using the old version of Forest. The current version has a linguistics library etc. – cfr Mar 2 '16 at 3:42
  • 1
    Or use anchor=parent for the tree? Or anchor=north if you don't update. – cfr Mar 2 '16 at 3:43
2

This code is updated for the current version of Forest (2.0.1 but should work with 2). You can regress it for version 1 as you wish. Aside from updating the code, all I've done is applied anchor=parent to the tree. I think the use of tabulars within what are already tabular environments is overly complex, but it seems to work even so.

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage[linguistics]{forest}
\forestset{
  my tree/.style={%
    for tree={%
      anchor=parent,
    },
    where n children=0{%
      tier=word,
      delay=with translation
    }{}
  },
  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={%
    append={%
      [#1,
        no edge,
        l=0,
        inner sep=0,
        outer ysep=0,
        before computing xy={l-=2pt}
      ]%
    }
  },
}
\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}
\usepackage{array}
\setlength{\extrarowheight}{1pt}
\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}%
}
\def\ibox#1{\mbox{}\setbox2=\hbox{$\scriptstyle #1$}\lower.2ex\vbox{\hrule
    \hbox{\vrule\kern1.25pt
      \vbox{\kern1.25pt\box2\kern1.25pt}\kern1.25pt\vrule}\hrule}}
\newcommand{\liste}[1]{%
  \mbox{%
    $%
    \left\langle\begin{tabular}{@{}>{\upshape\scshape}l@{}}#1\end{tabular}\right\rangle%
    $%
  }%
}
\begin{document}
\begin{forest}
  my tree,
  [\ms{head & \ibox{1}\\
    subcat & \liste{ }
  }
    [{\ibox{2} NP{[\textit{nom}]}}
    [er;he]]
    [\ms{
      head & \ibox{1}\\
      subcat & \liste{ \ibox{2} }
      }
      [\ibox{3} NP{[\textit{dat}]}
        [dem Mann;the man, roof]
      ]
      [\ms{
        head & \ibox{1}\\
        subcat & \liste{ \ibox{2}, \ibox{3} }
        }
        [\ibox{4} NP{[\textit{acc}]}
          [das Buch;the book, roof]
        ]
        [\ms{
          head & \ibox{1} \ms[verb]{
            vform & fin
          }\\
          subcat & \liste{ \ibox{2}, \ibox{3}, \ibox{4} }
          }
          [gibt;gives]
        ]
      ]
    ]
  ]
\end{forest}
\end{document}

anchored nodes

|improve this answer|||||

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.