ムウェ

ムウェ

次の MWE は、ドキュメントの例に基づいていますforestdotスタイル (記号で囲まれている%%%) は、ツリー内のドットのスタイル (主に色) を指定する引数を取ることになっています。名前付きの色には機能しますが、設定してもdot={draw=none}効果はありません。通常、draw/を設定するfillと、noneパスが色なしで描画/塗りつぶされます。

dotこの奇妙な効果の原因は何でしょうか? これは がを使用して定義されているという事実と関係があるのでしょうか\tikz+?

ムウェ

\documentclass{standalone}
\usepackage{forest}
\forestset{
  declare toks={elo}{}, % Edge Label Options
  anchors/.style={anchor=#1,child anchor=#1,parent anchor=#1},
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  dot/.style={tikz+={\draw[#1] (.child anchor) circle[radius=1.5pt];}},
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  decision edge label/.style n args=3{
    edge label/.expanded={node[midway,auto=#1,anchor=#2,\forestoption{elo}]{\strut$\unexpanded{#3}$}}
  },
  decision/.style={if n=1
    {decision edge label={left}{east}{#1}}
    {decision edge label={right}{west}{#1}}
  },
  text/.style={plain content},
  decision tree/.style={
    for tree={
      s sep=0mm,l=5mm,
      if n children=0{anchors=north}{
        if n=1{anchors=south east}{anchors=south west}},
      math content,
      /tikz/font=\footnotesize,
    },
    anchors=south, outer sep=2pt,
    dot={fill=white},for descendants={dot={fill}},
    delay={for descendants={split option={content}{;}{decision,content}}},
  }
}
\begin{document}
\begin{forest} decision tree
  [N,plain content
    [x;I,dot={draw=none,fill=red}] % 'draw=none' doesn't work here
    [x;I,dot={draw=red,fill=none}] % 'fill=none' doesn't work here
  ]
  % 'draw=none' works fine below
  \draw[draw=none](!1.anchor)--(!2.anchor)node[midway,above]{$x$};
\end{forest}
\end{document}

出力

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

答え1

draw=noneは、次のスタイルtikz+と同様に、では正常に動作します。dot

\begin{forest}
  [abc, dot={draw=none, fill=red}
  ]
\end{forest}

赤い点、引き分けなし

しかし、はtikzと同じではありませんtikz+tikz+は累積的です。したがって、

for descendants={%
  dot={fill},
},

次に、現在のノード (ここではルート) のすべての子孫に対して、スタイルdotが引数として実行されfill、後で使用するために次のコマンドがリストに追加されます。

\draw [fill] (.child anchor) circle [radius=1.5pt];

dotその後、特定のノードに再度適用すると、dot関連する引数で再度実行されます。たとえば、

dot={draw=none, fill=red}

後で使用する TikZ コマンドのリストにこれを追加します。

\draw [draw=none, fill=red] (.child anchor) circle [radius=1.5pt];

それで、このノードでは、ツリーが描画されたときに、次の 2 つのコマンドが順番に使用されることになります。

\draw [fill] (.child anchor) circle [radius=1.5pt];
\draw [draw=none, fill=red] (.child anchor) circle [radius=1.5pt];

最初のものは円を黒で描いて塗りつぶします。2番目は、全く同じ場所に、赤で塗りつぶされた別の円を追加します。出力に表示されるのは次のようになります。円が重なり合って描かれています。

もしあなたが最後の使用dotを有効にするには、定義をtikzではなくを使用するように変更しますtikz+。ただし、 を使用するdotと、他のtikzノードに/ tikz+/を使用します。これが問題でなければ、解決策は非常に簡単です。これが問題であれば、望みどおりに動作するようにするためにもう少し工夫するか、すべての呼び出しが確実に発生する+tikzようにする必要があります。dot前にその他の追加は TikZ コマンドのリストに行われます。

以下は、ノードごとに最大 1 つのドットのポリシーを適用する単純なケースの変更されたコードです。

\documentclass[tikz,multi,border=10pt]{standalone}
\usepackage{forest}
\forestset{
  declare toks={elo}{}, % Edge Label Options
  anchors/.style={%
    anchor=#1,
    child anchor=#1,
    parent anchor=#1,
  },
  dot/.style={%
    tikz={%
      \draw [#1] (.child anchor) circle [radius=1.5pt];
    },
  },
  decision edge label/.style n args=3{
    edge label/.expanded={%
      node [midway, auto=#1, anchor=#2, \forestoption{elo}] {\strut$\unexpanded{#3}$}
    }
  },
  decision/.style={%
    if n=1{%
      decision edge label={left}{east}{#1},
    }{%
      decision edge label={right}{west}{#1},
    }
  },
  decision tree/.style={
    for tree={
      s sep=0mm,
      l=5mm,
      if n children=0{anchors=north}{
        if n=1{%
          anchors=south east,
        }{%
          anchors=south west,
        },
      },
      math content,
      font=\footnotesize,
    },
    anchors=south,
    outer sep=2pt,
    dot={%
      fill=white,
    },
    for descendants={%
      dot={fill},
    },
    delay={%
      for descendants={%
        split option={content}{;}{decision,content},
      },
    },
  }
}
\begin{document}
\begin{forest}
  decision tree
  [N, plain content
    [x;I, dot={draw=none, fill=red}
    ]
    [x;I, dot={draw=red, fill=none}
    ]
  ]
\end{forest}
\end{document}

ノードごとにドットは 1 つだけです。

関連情報