增加关于森林中两个女儿的规范,其中一个具有特殊地位

增加关于森林中两个女儿的规范,其中一个具有特殊地位

我想要生成下图forest

特斯尼尔氏柱

因此,我要寻找的是一种样式规范,它表明女儿 1(frapp)和女儿 2(ant)共同与 A 相关。女儿 2(ant)更为重要,这在图中以向右下方弯曲的向下线标记ant

有没有办法将其集成到下面的示例中?

\documentclass{article}

\usepackage{forest}


\begin{document}

\begin{forest}
[un exemple
  [A
    [frapp]
     [ant] ] ]
\end{forest}


\end{document}

这是涉及三个元素的两个关系:A 是 frapp 和 ant 的母元素。而 ant 是 A 内部的头部(最重要的元素)。有没有一种使用forest样式来实现这一点的好方法?

编辑:

我按照建议做了一些实验edge path。这是我得到的:

\documentclass{article}

\usepackage{forest}

\forestset{
dg translation/.style={edge path={\noexpand\path[\forestoption{edge}]
(!u.parent anchor)-- +(0,-l)
(!p.north west)--(.north east)\forestoption{edge label};}}
}

\begin{document}

\begin{forest}
[un example
  [A
    [frapp, no edge]
     [ant, dg translation] ] ]
\end{forest}


\end{document}

得出的结果为:

在此处输入图片描述

一条长度向南的直线l和一条覆盖两个女儿的线。然后我必须将线抬高,使其再次处于 A 的水平(并添加一些曲线)。但我不知道如何得到距离。它不是,只是l稍微小一点。或者我可以从 A 的下方画出,但我不知道要向左和向右画多远,因为这取决于女儿的大小。

我还必须指定no edge另一个女儿。如果能避免这种情况,那就太好了。

编辑2:

好的,根据 cfr 的评论,我删除了no edge树中的规范:

\documentclass{article}

\usepackage{forest}

\forestset{
dg translation/.style={edge path={\noexpand\path[\forestoption{edge}]
(!u.parent anchor)-- +(0,-l)
(!p.north west)--(.north east)\forestoption{edge label};},!p.edge'={}}
}

\begin{document}

\begin{forest}
[un example
  [A
    [frapp]
     [ant, dg translation] ] ]
\end{forest}


\end{document}

但是我仍然不知道应该如何在 A 下方画出曲线。这里的评论对我没有帮助。

编辑3:

好的。我了解到了这一点:

\documentclass{article}

\usepackage{forest}
\usetikzlibrary{calc}


\forestset{
dg translation/.style={edge path={\noexpand\path[\forestoption{edge}, rounded corners=3pt]
% the line downwards
(!u.parent anchor)-- +($(0,-l)-(0,12pt)$)-- +($(12pt,-l)-(0,12pt)$)
% the horizontal line
($(!p.north west)+(0,l)-(0,14pt)$)--($(.north east)+(0,l)-(0,14pt)$)\forestoption{edge label};},!p.edge'={}}
}

\begin{document}

\begin{forest}
[un exemple
  [A
    [frapp]
     [ant, dg translation] ] ]
\end{forest}


\end{document}

这将产生以下图片:

在此处输入图片描述

有几件事让我不满意:代码包含手动向上移动 14pt。这不适用于其他字体大小。

另一个问题是我如何使水平线弯曲。我找到了一些影响线条的方法tikz,但这些是路径的选项,似乎不可能有两个不同的边缘路径forest。因此,如果我指定选项,例如rounded corners它会影响路径的所有部分,但我想有两条单独的路径。有办法吗?

答案1

编辑我原来的答案只适用于森林版本 1.下面的代码不仅更简单,而且版本 1 和版本 2 运行得同样好。


这是我的解决方案。请注意,Stefan Müller 的no edge兄弟设置解决方案比我node walk在此代码的原始版本中明确使用的要简洁得多,尽管下面的更新版本仍然更简单。

我使用tikz键来绘制弯曲的水平线,而不是试图将其放入路径中。这样可以很容易地确保我引用的节点存在,尽管如果稍加注意,edge这可以合并到绘图中。edge

当然,“VIN”在节点上相当于人们的“VIP”。

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
  for tree={
    parent anchor=south,
    child anchor=north,
  },
  vin/.style={
    child anchor=south west,
    edge path={
      \noexpand\path [draw, \forestoption{edge}]
      (!u.parent anchor) -- (!u.parent anchor |- .west) [out=-90, in=180] to (.child anchor)\forestoption{edge label};
    },
    for parent={
      before packing={
        tikz={
          \draw (!1.north west |- .parent anchor) [out=30, in=170] to (.parent anchor) [out=-10, in=-150] to (!l.north east |- .parent anchor);
        },
      },
    },
    before typesetting nodes={
     !p.no edge,
    },
  }
  [un exemple
    [A
      [frapp
      ]
      [ant, vin
      ]
    ]
  ]
\end{forest}
\end{document}

弯曲的路径

相关内容