如何在实线箭头旁边插入“是”和“否”?
我尝试node [near end, right] {Yes}
在每个节点和子声明之后放置它,但是这只会扰乱决策树的流程。
代码
\noindent
\begin{figure}[htbp]
\centering
\sffamily
\tikzstyle{level 1}=[level distance=1.5cm, sibling distance=4.25cm]
\tikzstyle{level 2}=[level distance=1.5cm, sibling distance=2.25cm]
\tikzstyle{level 3}=[level distance=1.5cm, sibling distance=4.25cm]
\tikzstyle{level 4}=[level distance=1.5cm, sibling distance=2.25cm]
\tikzset{decision/.style={
draw=gray-5-border, solid, fill=gray-e-bg, rectangle,
anchor=north,
inner sep=2mm, outer sep=0, text centered, growth parent anchor=south}
}
\tikzset{prediction/.style={
draw=gray-4-border, solid, fill=gray-d-bg, ellipse,
anchor=north,
inner sep=2mm, outer sep=0, text centered, growth parent anchor=south}
}
\tikzset{arrow/.style={-latex, thick}}
\tikzset{arrow-dashed/.style={-latex, dashed, thick}}
\begin{tikzpicture}
\node [prediction] {+0.5} [dashed, -latex, thick, ->]
child {
node [decision] {$a < 4.5$} [->]
child {
node [prediction] {-0.7} [solid, -latex, thick, ->]
child {
node [decision] {$b > 1$} [dashed, -latex, thick, ->]
child {
node [prediction] {+0.4} [solid, -latex, thick, ->]
}
child {
node [prediction] {-0.2} [solid, -latex, thick, ->]
}
}
child {
node [decision] {$a > 2$} [dashed, -latex, thick, ->]
child {
node [prediction] {-0.1} [solid, -latex, thick, ->]
}
child {
node [prediction] {+0.1} [solid, -latex, thick, ->]
}
}
}
child {
node [prediction] {+0.2} [solid, -latex, thick, ->]
}
}
child {
node [decision] {$b > 0$}
child {
node [prediction] {+0.3} [solid, -latex, thick, ->]
}
child {
node [prediction] {-0.6} [solid, -latex, thick, ->]
}
}
;
\end{tikzpicture}
\caption{A diagram of Freund and Mason's general alternating decision tree}
\label{fig:diagram-adt}
\end{figure}
输出
答案1
你需要使用
node [prediction {$-0.7$} edge from parent [dashed] node [near end, right] {Yes}
我还要补充-latex, thick
一点edge from parent
,这样您就不必每次都重复常用选项。
我还->
从选项中删除了它,因为你已经-latex
在里面了,它将->
覆盖-latex´ with
-to (or to whatever
>`设置)。
请注意,我还使用了数学模式,以便-0.7
正确排版减号(建议用于text depth=+0pt
节点,因为减号增加了一定的深度,但也是如此+
)。