我正在尝试用 LaTeX 制作这个概率树:
我尝试使用该tikz
软件包,但一直遇到一些问题。这是我目前为止得到的最好的软件包(链接:https://www.writelatex.com/855538qcgkps#/1917915/):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\pagestyle{empty}
\tikzstyle{level 1}=[level distance=3cm, sibling distance=3cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]
\tikzstyle{bag} = [circle, minimum width=10pt, inner sep=2pt]
\tikzstyle{end} = [circle, minimum width=3pt, fill, inner sep=0pt]
\begin{tikzpicture}[grow=right, sloped]
\node[bag]{}
child {
node[bag] {O}
child {
node[end, label=right:{O}] {}
edge from parent
node[above] {}
node[below] {$1-\lambda$}
child {
node[end, label=right: {O ...}] {}
edge from parent
node[above] {}
node[below] {$1-\lambda$}
}
child {
node[end, label=right: {S ...}] {}
edge from parent
node[above] {$\lambda$}
node[below] {}
}
}
child {
node[end, label=right: {S}] {}
edge from parent
node[above] {$\lambda$}
node[below] {}
}
edge from parent
node[above] {}
node[below] {$1-\lambda$}
}
child {
node[bag] {S}
child {
edge from parent
node[above] {1}
node[below] {}
node[bag] {O'}
child {
edge from parent
node[above] {$1$}
node[below] {$$}
edge from parent
}
}
edge from parent
node[above] {$\lambda$}
node[below] {}
};
\end{tikzpicture}
\end{document}
正如您所看到的,它们完全不同,但我似乎无法继续前进,您能帮助我吗?我似乎无法意识到错误是什么。
最好的。
答案1
我建议你使用强大的forest
包(基于 PGF/TikZ 构建):
\documentclass{article}
\usepackage{amsmath}
\usepackage{forest}
\tikzset{
dot/.style={circle,draw,inner sep=1.2,fill=black},
}
\newcommand\Labeli{%
node[below left,midway,xshift=3pt,font=\small]{$(1-\lambda)$}
node[above right,midway,xshift=-3pt,font=\small]{$0$}%
}
\newcommand\Labelii{%
node[above left,midway,xshift=3pt,font=\small]{$S$}
node[below right,midway,xshift=-3pt,font=\small]{$(\lambda)$}%
}
\newcommand\Labeliii{%
node[above,midway,font=\small]{$0'$}
node[below,midway,font=\small]{$(1)$}%
}
\begin{document}
\begin{forest}
[ ,name=a,for tree={s sep=60pt,l sep=2cm,dot,grow=0},
[ ,name=b,edge label={\Labeli}
[ ,name=c,edge label={\Labeli}
[ ,name=d,edge label={\Labeli} ]
[ ,name=e,edge label={\Labelii} ]
]
[ ,edge label={\Labelii}
[ ,name=f,edge label={\Labeliii} ]
]
]
[ ,edge label={\Labelii}
[ ,edge label={\Labeliii}
[ ,name=g,edge label={\Labeliii} ]
]
]
]
\foreach \Nodo in {d,e,f,g}
\node[anchor=west,xshift=3pt] at (\Nodo) {$\cdots$};
\node[yshift=-1cm,name= tiii,font=\small] at (d) {$t+3$};
\node[name= tii,font=\small] at (c|-tiii) {$t+2$};
\node[name= ti,font=\small] at (b|-tiii) {$t+1$};
\node[name= t,font=\small] at (a|-tiii) {$t$};
\end{forest}
\end{document}