森の中の特別な地位にある2人の娘に関する詳細を追加する

森の中の特別な地位にある2人の娘に関する詳細を追加する

次の図を作成したいと思います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}

これは 3 つの要素を含む 2 つの関係です。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と、2 人の娘を覆う線。次に、線を再び A の高さになるように上げます (そして、曲線を追加します)。しかし、距離をどうやって測るかはわかりません。l少し短くなるだけです。あるいは、A の下から描くこともできますが、娘のサイズによって左右されるので、左と右にどのくらいの距離を測るかはわかりません。

もう一人の娘についても指定する必要がありましたno edge。これを何とか回避できれば、とても助かります。

編集2:

OK、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:

OK。ここまで来ました。

\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}

これにより、次の図が生成されます。

ここに画像の説明を入力してください

いくつか不満な点があります。コードには、手動で 14 ポイント上方にシフトする機能が含まれています。これは他のフォント サイズでは機能しません。

もう 1 つの質問は、水平線を曲線にする方法です。 の線に影響を与えるいくつかの方法を見つけましたtikzが、これらはパスのオプションであり、 で 2 つの異なるエッジ パスを持つことはできないようですforest。したがって、 のようなオプションを指定すると、rounded cornersパスのすべての部分に影響しますが、2 つの別々のパスが必要です。これを行う方法はありますか?

答え1

編集私の最初の答えは、バージョン 1。以下のコードはよりシンプルであるだけでなく、バ​​ージョン 1 とバージョン 2 の両方で同様に機能します。


no edgeこれが私の解決策です。兄弟を設定するための Stefan Müller の解決策は、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}

曲がりくねった道

関連情報