将兄弟姐妹与森林中的复杂内容对齐

将兄弟姐妹与森林中的复杂内容对齐

我有以下代码,我希望 AVM 在顶部对齐。两个 PHON 值应位于同一高度。我为所有节点设置了 base=top 选项,但这不起作用。

\documentclass{article}
\usepackage{forest}

\forestset{.style={for tree={parent anchor=south, child anchor=north,align=center,base=top}}}



\usepackage{array}


\makeatletter

\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{\sliste}[1]{%
\mbox{%
$\left\langle\mbox{\upshape\scshape #1}\right\rangle$}%
}

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


\newcommand{\phonliste}[1]{%
\mbox{%
$%
%
\left\langle \mbox{\normalfont\itshape#1} \right\rangle%
$%
%\\[-1.5mm]
}%
}


\setlength{\extrarowheight}{1pt}

\def\ms{\futurelet\msLook\msdecide}
\def\msdecide{\ifx\msLook[\let\next=\xxtms%
\else\let\next=\xxms\fi\next}
%
\def\xxtms[#1]#2{%
\mbox{%
\tabcolsep0pt\arraycolsep0pt%
$%
\left[%
\begin{tabular}{>{\upshape\scshape}l@{\hspace{5pt}}>{\normalfont\itshape}l}%
#2%
\multicolumn{2}{>{\normalfont\itshape}l}{#1}%
\end{tabular}%
\right]%
$%
}%
\vspace{1mm}%
}

\def\xxms#1{%
\mbox{%
\tabcolsep0pt\arraycolsep0pt%
$%
\left[%
\begin{tabular}{>{\upshape\scshape}l@{\hspace{5pt}}>{\normalfont\itshape}l}%
#1%
\end{tabular}%
\rule{0mm}{5mm}%
\right]%
$%
}%
\vspace{1mm}%
}



\def\onems{\tabcolsep0pt\arraycolsep0pt\futurelet\onemsLook\onemsdecide}
\def\onemsdecide{\ifx\onemsLook[\let\next=\xxtonems%
\else\let\next=\xxonems\fi\next}
%
\def\xxtonems[#1]#2{%
$\left[%
\begin{tabular}{>{\upshape\scshape}l}%
#2%
{\normalfont\itshape #1}% 
\end{tabular}% 
\right]$%
\vspace{1mm}%
}

\def\xxonems#1{%
\mbox{%
$%
\left[%
\begin{tabular}{>{\upshape\scshape}l}%
#1%
\end{tabular}%
\rule{0mm}{5mm}%
\right]%
$%
}%
\vspace{1mm}%
}

\makeatother

\begin{document}


  \begin{forest}
%    anchor=base,base=top
    baseline
    [
      mother node
      [ \onems{
        phon \phonliste{ nach Brüssel zum Demonstrieren }\\
        cat|head|dsl local \\
        cont|rels  \ibox{8}  \\
         }, base=top ]
      [   \onems{
        phon \phonliste{ ist Gerd Knecht nicht gefahren }\\
        cat|head|dt \sliste{ \ibox{1} }\\[1mm]
                                 cont \ms{ ltop & \ibox{4}\\
                                           rels & \ibox{7} $\oplus$ \ibox{2} $\oplus$ \liste{ \ibox{3} \ms[nicht-rel]{
                                                                                                           arg & \ibox{5} \\
                                                                                                          } } $\oplus$ \ibox{6}  \\
                                             }\\
        } ]]
\end{forest}


\end{document}

答案1

base=top仅当节点是锚定在基线上的多行节点时才有效。但这里的情况并非如此。尽管节点内有多行,但在forest看到内容时,它只是一个框。因此,您可以在框内调整对齐方式。更好的办法可能是根本不以这种方式处理内容,而是利用 的forest表格对齐方式。也就是说,您可以使用foresttikz样式来执行当前\defs 正在做的事情。或者无论如何,它们正在做的大部分事情。但是,基于您当前代码的快速解决方案是指定anchor=north

对齐顶部

\documentclass{article}
\usepackage{forest}
\usepackage{array}
\makeatletter
\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{\sliste}[1]{%
  \mbox{%
    $\left\langle\mbox{\upshape\scshape #1}\right\rangle$}%
}
\newcommand{\liste}[1]{%
  \mbox{%
    $%
    \left\langle\begin{tabular}{@{}>{\upshape\scshape}l@{}}#1\end{tabular}\right\rangle%
    $%
    %\\[-1.5mm]
  }%
}
\newcommand{\phonliste}[1]{%
  \mbox{%
    $%
    %
    \left\langle \mbox{\normalfont\itshape#1} \right\rangle%
    $%
    %\\[-1.5mm]
  }%
}
\setlength{\extrarowheight}{1pt}
\def\ms{\futurelet\msLook\msdecide}
\def\msdecide{\ifx\msLook[\let\next=\xxtms%
  \else\let\next=\xxms\fi\next}
%
\def\xxtms[#1]#2{%
  \mbox{%
    \tabcolsep0pt\arraycolsep0pt%
    $%
    \left[%
    \begin{tabular}{>{\upshape\scshape}l@{\hspace{5pt}}>{\normalfont\itshape}l}%
      #2%
      \multicolumn{2}{>{\normalfont\itshape}l}{#1}%
    \end{tabular}%
    \right]%
    $%
  }%
  \vspace{1mm}%
}
\def\xxms#1{%
  \mbox{%
    \tabcolsep0pt\arraycolsep0pt%
    $%
    \left[%
    \begin{tabular}{>{\upshape\scshape}l@{\hspace{5pt}}>{\normalfont\itshape}l}%
      #1%
    \end{tabular}%
    \rule{0mm}{5mm}%
    \right]%
    $%
  }%
  \vspace{1mm}%
}
\def\onems{\tabcolsep0pt\arraycolsep0pt\futurelet\onemsLook\onemsdecide}
\def\onemsdecide{\ifx\onemsLook[\let\next=\xxtonems%
  \else\let\next=\xxonems\fi\next}
%
\def\xxtonems[#1]#2{%
  $\left[%
  \begin{tabular}{>{\upshape\scshape}l}%
    #2%
    {\normalfont\itshape #1}%
  \end{tabular}%
  \right]$%
  \vspace{1mm}%
}
\def\xxonems#1{%
  \mbox{%
    $%
    \left[%
    \begin{tabular}{>{\upshape\scshape}l}%
      #1%
    \end{tabular}%
    \rule{0mm}{5mm}%
    \right]%
    $%
  }%
  \vspace{1mm}%
}
\makeatother
\forestset{.style={for tree={parent anchor=south, child anchor=north, anchor=north, align=center}}}

\begin{document}
  \begin{forest}
    %    anchor=base,base=top
    baseline
    [
    mother node
    [ \onems{
      phon \phonliste{ nach Brüssel zum Demonstrieren }\\
      cat|head|dsl local \\
      cont|rels  \ibox{8}  \\
    }, base=top ]
    [   \onems{
      phon \phonliste{ ist Gerd Knecht nicht gefahren }\\
      cat|head|dt \sliste{ \ibox{1} }\\[1mm]
      cont \ms{ ltop & \ibox{4}\\
        rels & \ibox{7} $\oplus$ \ibox{2} $\oplus$ \liste{ \ibox{3} \ms[nicht-rel]{
            arg & \ibox{5} \\
          } } $\oplus$ \ibox{6}  \\
      }\\
    } ]]
  \end{forest}
\end{document}

请注意,在 LaTeX 文档中,\newcommand和朋友比和朋友更可取。或者,可用于更灵活的定义。(除非您使用语法,否则等有时仍然是必要的,但最好只在真正必要时使用它们。)\defxparse\defexpl3

相关内容