语言学森林 - 像 qtree 中一样的比例对齐

语言学森林 - 像 qtree 中一样的比例对齐

我对森林还不熟悉。是否有一种样式(或下面的修改)可以像树 B 中一样在树 A 中产生空终端节点 F3 和 F4 的对齐?

\documentclass{standalone}
\usepackage{forest}
%\forestset{nice nodes/.style={for tree={inner sep=0pt,s sep=.2in,align=center, anchor=north}},default preamble=nice nodes, }
\useforestlibrary{linguistics}
\forestapplylibrarydefaults{linguistics}
\begin{document}

Tree A:

\begin{forest}
[
[DP, name=target[a labelled\\ subtree, roof]]  
[F$_4$P[F$_4$]
[F$_3$P[F$_3$]
[F$_2$P[F$_2$][\hspace{10pt}F$_1$P $\Rightarrow$ something, 
name=t[is there a way\\to move this label\\to the right?, roof]]]]]]]
\end{forest}

Tree B:

\begin{forest}
[
[DP, name=target[a labelled\\ subtree, roof]]  
[F$_4$P[F$_4$[$\emptyset$]]
[F$_3$P[F$_3$[]]
[F$_2$P[F$_2$][\hspace{10pt}F$_1$P $\Rightarrow$ something, 
name=t[I miss qtree, roof]]]]]]]
\end{forest}
\end{document}

另一个问题是将节点标签(树中的 F4P)向右移动的问题,因此它不相对于节点居中。这是我得到的结果:

在此处输入图片描述

PS。我使用的骨架可以容忍 qtree 和 tikz-qtree,但不能容忍 XeLaTeX 中的 qtree 和 tikz-qtree 中的箭头,所以我想我需要坚持使用森林。这就是为什么我试图在森林中拥有一棵漂亮的比例树,而不是简单地使用 qtree。

答案1

我认为对于您的主要问题,您可能只是想添加fit=band到树中。

<code>适合=乐队</code>

请注意,这anchor=center是的默认值linguistics

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage[linguistics]{forest}
\forestset{
  nice nodes/.style={
    for tree={
      inner sep=0pt,
      fit=band,
    },
  },
  default preamble=nice nodes,
}
\begin{document}
\begin{forest}
  [
    [DP, name=target
      [nodes F$_3$ and F$_4$ do\\
      align appropriately\\
      (I think)\\
      wrt F$_2$, roof
      ]
    ]
    [F$_4$P
      [F$_4$]
      [F$_3$P
        [F$_3$]
        [F$_2$P
          [F$_2$]
          [\hspace{10pt}F$_1$P$\Rightarrow$something, name=t
            [is there a way\\to move this label\\to the right?, roof
            ]
          ]
        ]
      ]
    ]
  ]
\end{forest}
\end{document}

我不太清楚你想把什么移到哪里。你所说的节点label实际上不是label,而是 节点content。节点可以有labels 和contents ,所以这可能会造成混淆。

您可以将右下角的节点向右(或向左)移动。但是,我不确定这是否真的是您的意思。

            [is there a way\\to move this label\\to the right?, roof, xshift=10pt
            ]

右移

为了避免屋顶不倾斜,我们可以重新定义edge path

修理屋顶

            [is there a way\\to move this label\\to the right?, xshift=10pt, edge path'={(!u.parent anchor) ++(5pt,0) -- (.north east) -- (.north west) -- cycle}
            ]

如果您经常需要这个,那么样式会很方便。

  shift with roof/.style={
    xshift=#1,
    edge path'={(!u.parent anchor) ++(#1/2,0) -- (.north east) -- (.north west) -- cycle}
  },

然后我们就可以写

            [is there a way\\to move this label\\to the right?, shift with roof=10pt
            ]

产生与上面相同的输出。

您可以通过增加根子节点之间的距离来使顶部不那么“尖锐”。可能有点极端:

不那么“尖锐”

  [, s sep'+=20pt

稍微不那么极端可能会更好。

不那么极端

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage[linguistics]{forest}
\forestset{
  nice nodes/.style={
    for tree={
      inner sep=0pt,
      fit=band,
    },
  },
  default preamble=nice nodes,
  shift with roof/.style={
    xshift=#1,
    edge path'={(!u.parent anchor) ++(#1/2,0) -- (.north east) -- (.north west) -- cycle}
  },
}
\begin{document}
\begin{forest}
  [, s sep'+=10pt
    [DP, name=target
      [nodes F$_3$ and F$_4$ do\\
      align appropriately\\
      (I think)\\
      wrt F$_2$, roof
      ]
    ]
    [F$_4$P
      [F$_4$]
      [F$_3$P
        [F$_3$]
        [F$_2$P
          [F$_2$]
          [\hspace{10pt}F$_1$P$\Rightarrow$something, name=t
            [is there a way\\to move this label\\to the right?, shift with roof=10pt
            ]
          ]
        ]
      ]
    ]
  ]
\end{forest}
\end{document}

答案2

\documentclass{standalone}
\usepackage{forest}
\forestset{
  nice nodes/.style={
    for tree={
      inner sep=1pt, s sep=12pt,
      fit=band,
    },
  },
  default preamble=nice nodes,
}
\useforestlibrary{linguistics}
\forestapplylibrarydefaults{linguistics}
\begin{document}

\begin{forest}
 [
 [DP, name=target[nodes F$_3$ and F$_4$ do\\ not align vertically\\ wrt           F$_2$, roof]]  
 [F$_4$P[F$_4$]    [F$_3$P[F$_3$]
  [F$_2$P[F$_2$]    [F$_1$P, name=t[I miss qtree, roof]] 
{ \draw (.east) node[right]{$\Rightarrow$ \textit{adjective}}; } ]]]]]
   %\draw[->] (t) to[out=south west,in=south] (target);
\end{forest}
\end{document}

这给了我这个:

在此处输入图片描述

相关内容