微量元素

微量元素

以下 MWE 是基於forest文件中的範例。樣式dot(在符號之間標記%%%)應該採用一個參數來指定樹中點的樣式(主要是顏色)。雖然它適用於命名顏色,但設定dot={draw=none}沒有效果。通常,將draw/設定fillnone應該以無顏色繪製/填充路徑。

是什麼導致了這種奇怪的效應?這與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];

因此,現在該節點發生的情況是,當繪製樹時,將一個接一個地使用這兩個命令:

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

第一個繪製圓圈並將其填充為黑色。第二個在完全相同的位置添加了另一個圓圈,未繪製但用紅色填充。所以你在輸出中看到的是圓圈,一個又一個。

如果你只想要最後的為了有效使用dot,請將定義更改為 usetikz而不是tikz+。但是,使用dot將覆蓋任何其他使用tikz//作為節點tikz++tikz如果這不是問題,那麼解決方案就非常簡單。如果這是一個問題,您需要做更多的練習才能使其按預期工作或確保發生所有dot調用任何其他新增都會新增到 TikZ 命令清單中。

以下是針對簡單情況的變更後的程式碼,它強制執行每個節點至多一個點的策略:

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

每個節點只有一個點!

相關內容