我想使用下面的代码绘制像图中这样的过程,但是,出现了一些问题,有人可以帮帮我吗?
\usepackage[latin1]{inputenc}
\usetikzlibrary{trees}
\usepackage{verbatim}
\tikzstyle{level 1}=[level distance=1.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=1.5cm, sibling distance=2cm]
\tikzstyle{bag} = [text width=20em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]
\begin{tikzpicture}[grow=down]
\node[bag] { $(B)$}
child {
node[bag] {$(R_{good})$}
child {
node[bag] {$(and)$}
edge from parent
node[right] {$and$}
}
edge from parent
node[right] {$t$}
};
\end{tikzpicture}
答案1
你想要类似的东西吗:
代码如下:
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\tikzset{level 1/.style={level distance=1.5cm, sibling distance=3.5cm}}
\tikzset{level 2/.style={level distance=1.5cm, sibling distance=2cm}}
\tikzset{bag/.style={text width=20em, text centered,yshift=-0.2cm}}
\begin{document}
\begin{tikzpicture}[grow=down, -stealth]
\node[bag]{$(B)$}
child{ edge from parent node[right]{t}; \node[bag]{$(Rgood)$}
child{ edge from parent node[right]{and}; \node[bag]{$(and)$}
child[missing]
child{ edge from parent node[right=0.1cm]{it}; \node[bag]{$(path1)$}}
child{ edge from parent node[right=0.1cm]{else}; \node[bag]{$(path2)$}}
}
};
\end{tikzpicture}
\end{document}
我实际上删除了未使用的样式,用等效end
的语法更改了弃用语法。此外,对于叶子,我利用选项让其正好位于前一个下方tikzstyle
tikzset
missing
path1
and
。您可以通过将其插入为环境选项来添加箭头tikzpicture
。