在森林树中对齐 AVM

在森林树中对齐 AVM

我用forest它来排版树。这确实很有效,但不知何故,AVM 的处理方式与普通文本不同。我猜这与 AVM 中表格环境的基线有关。我尝试t在表格中设置选项,但这不起作用。那么,我如何才能通过以下方式获得 AVM 与树中其他节点之间的对齐:

在此处输入图片描述

这是代码:

\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

此代码已针对 Forest 的当前版本(2.0.1,但应该适用于 2.0.1)进行了更新。您可以根据需要将其回归到版本 1。除了更新代码外,我所做的一切都应用于anchor=parent树。我认为在已经是表格的环境中使用表格过于复杂,但即使如此,它似乎仍然有效。

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

锚定节点

相关内容