如何在我的决策树中绘制正方形和圆形?

如何在我的决策树中绘制正方形和圆形?

我想创建一个如下所示的决策树。

决策树

\tikzstyle{decision} = [rectangle, minimum height=18pt, minimum width=18pt, draw=blue, fill=none, ultra thick, inner sep=0pt]
\tikzstyle{chance} = [circle, minimum width=18pt, draw=blue, fill=none, ultra thick, inner sep=0pt]
\tikzstyle{line} = [draw=none]

答案1

您可以选择每个孩子各自的形状。

不过,你还可以做很多事情,包括不需要硬编码。我对 Ti 了解不多Z 树/思维导图,但有一个教程在 TiZ 文档,例子在 TeXample 上,有很多可以画树的包(例如forest或者tikz-qtree等),以及此网站上的标签。

\documentclass[border=1cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}[%
level 1/.style={sibling distance=5cm},
level 2/.style={sibling distance=3cm},
every node/.style = {draw, minimum width=1.5cm, minimum height=.75cm, anchor=north},
edge from parent path={(\tikzparentnode.south) -- (\tikzchildnode.north)}]
]
\node[shape=ellipse, minimum height=1.25cm, minimum width=2cm] {R}
child { node[shape=rectangle, rounded corners] {A}
    child { node[shape=rectangle] {A} 
        child { node[shape=ellipse] {B} }
        child { node[shape=ellipse] {B} }
    }
    child { node[shape=ellipse] {B} }
}
child { node[shape=rectangle, rounded corners] {A} 
    child { node[shape=ellipse] {B} }
    child { node[shape=ellipse] {B} }
};
\end{tikzpicture}

\end{document}

截屏

使用tikzstyle您定义的:

\documentclass[border=1cm]{standalone}

\usepackage{tikz}

\tikzstyle{decision} = [rectangle, minimum height=18pt, minimum width=18pt, draw=blue, fill=none, ultra thick, inner sep=0pt]
\tikzstyle{chance} = [circle, minimum width=18pt, draw=blue, fill=none, ultra thick, inner sep=0pt]
\tikzstyle{line} = [draw=none]

\begin{document}

\begin{tikzpicture}[%
level 1/.style={sibling distance=5cm},
level 2/.style={sibling distance=3cm},
every node/.style = {draw},
edge from parent path={(\tikzparentnode.south) -- (\tikzchildnode.north)}]
]
\node[chance] {R}
child { node[decision] {A}
    child { node[decision] {A} 
        child { node[chance] {B} }
        child { node[chance] {B} }
    }
    child { node[chance] {B} }
}
child[decision] { node {A} 
    child { node[chance] {B} }
    child { node[chance] {B} }
};
\end{tikzpicture}

\end{document}

截屏

相关内容