添加有關森林中兩個女兒的說明,其中一個具有特殊地位

添加有關森林中兩個女兒的說明,其中一個具有特殊地位

我想用 產生下圖forest

特斯尼埃幹

所以我正在尋找的是一個樣式規範,它說女兒 1 (frapp) 和女兒 2 (ant) 一起與 A 相關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。


這是我的解決方案。請注意,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}

彎曲的路徑

相關內容