获取森林中空节点的直线

获取森林中空节点的直线

我有以下几棵树,我希望与红线平行的线是直线。目前它们是两条独立的线,但应该是一条直线。这可能吗?

在此处输入图片描述

\documentclass{article}

\usepackage{forest}
\useforestlibrary{linguistics}
\forestapplylibrarydefaults{linguistics}

% 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,anchor=north,base=bottom},
% This would align trees to the baseline. We do not want this for TAG
% where several trees have to be aligned with respect to their center.
%    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
    }
  },
}


\forestset{
     empty nodes/.style={
     delay={where content={}{shape=coordinate,for siblings={anchor=north}}{}}
     },
sm edges without translation/.style={for tree={parent anchor=south, child anchor=north,base=bottom},
                 where n children=0{tier=word}{}
                 }
}


    \begin{document}


\begin{forest} 
empty nodes
[{}
  [X \\ {[\textit{u}F]}]
  [{}
    [Y \\ {[F v]}, roof]]]
\end{forest}


\begin{forest}
        sm edges without translation, empty nodes
        [{}
        [X \\ {[\textit{u}F v]}]
        [{}
        [Y \\ {[F v]}, roof]]]
\end{forest}


\end{document}

编辑: 该问题似乎与有关roof在此处输入图片描述

\documentclass{article}

\usepackage{forest}
\useforestlibrary{linguistics}
\forestapplylibrarydefaults{linguistics}



    \begin{document}


\begin{forest} 
nice empty nodes
[{}
  [X \\ {[\textit{u}F]}]
  [{}
    [Y \\ {[F v]}, roof]]]
\end{forest}
\hspace{2cm}
\begin{forest} 
nice empty nodes
[{}
  [X \\ {[\textit{u}F]}]
  [{}
    [Y]
    [Z]]]
\end{forest}



\end{document}

答案1

正如 @cfr 在评论中指出的那样,您想要修改的路径fixed edge angles不是 的一部分roof

屋顶的尺寸由其内容物的尺寸决定。

所以我认为有两种可能的解决方案。

一种方法是使用幻像节点手动绘制屋顶。在此代码中,我制作了一个宏来包装特征,[...]否则forest会被绘制在屋顶下的节点中的括号所混淆。

另一种可能性(可能更容易)是将屋顶的内容放在一个固定大小的盒子里\makebox。我1.5em只是估算了一下宽度。

\documentclass{article}

\usepackage[linguistics]{forest}

\begin{document}
\newcommand{\brk}[1]{[#1]}

\begin{forest} 
nice empty nodes
[
  [X \\ {\brk{\textit{u}F}}]
  [
    [\phantom{Y},name=Y]
    [\phantom{Z},name=Z]]]
\draw (Y.north)  -- (Z.north) node [midway,below,align=center] {Y\\{\brk{F v}}};
\end{forest}

\begin{forest} 
nice empty nodes
[
  [X \\ {[\textit{u}F]}]
  [
    [Y \\ {\makebox[1.5em]{[F v]}}, roof]]]
\end{forest}

\end{document}

代码输出

相关内容