
다음 MWE는 설명서의 예를 기반으로 합니다 forest
. 스타일 dot
(기호 사이에 표시됨 %%%
)은 트리의 점에 대한 스타일(주로 색상)을 지정하는 인수를 취한다고 가정됩니다. 명명된 색상에 대해서는 작동하지만 설정은 dot={draw=none}
효과가 없습니다. 일반적으로 draw
/ fill
to를 설정하면 none
경로를 색상 없이 그리거나 채우는 것으로 간주됩니다.
이 이상한 효과의 원인은 무엇입니까? 이것이 dot
를 사용하여 정의된 사실과 관련이 있습니까 \tikz+
?
MWE
\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
사용으로 정의를 변경하세요 . 그러나 will을 사용하면 모든 항목을 덮어씁니다.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}