将顶部的节点与森林对齐

将顶部的节点与森林对齐

我有以下代码:

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

它生成以下树:

在此处输入图片描述

左侧的 NP 与 AVM 中间对齐。在sm edgesI中base=top,它与 不同base=bottom,但结果更像人们所期望的base=center。这是 中的错误forest还是有其他方法可以将文本对齐到顶部?

答案1

只需尝试anchor=north

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

ps 已经完成了关于 HPSG 的硕士论文:)

在此处输入图片描述

答案2

假设你想要这样的东西:

输出(目标)

您拥有的大部分代码在最好的情况下是不必要的,在最坏的情况下是适得其反的。特别是,所有的default preamble东西都可以被砍掉。翻译装置也是可消耗的,尽管如果您在其他树中需要它,您可以将其保留在原处(此树的输出将保持不变)。

这给你留下了一个更简单的问题,可以通过设置anchor=parent树来解决。

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

相关内容