LaTeX 概率树

LaTeX 概率树

请告诉我概率树由 Kjell Magne Fauske 于 2006-12-14 发布,可以用三个分支来完成,而不只是两个。

答案1

  • 要添加另一个“Bag 2”分支,请添加另一个node[bag]结构。
  • 要添加另一个终止分支,请将另一个添加child { node[end] {}}node[bag]结构中。

您只需复制并粘贴正确的部分即可实现它。

这是一个简化的例子http://www.texample.net/tikz/examples/probability-tree/其中每种分支又添加了一个:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}

% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]

% Define styles for bags and leafs
\tikzstyle{bag} = [text width=4em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]

\begin{tikzpicture}[grow=right, sloped]
\node[bag] {Bag 1}
    child {
        node[bag] {Bag 2}% This is the first of three "Bag 2"
        child {
                node[end] {}
            }
            child {
                node[end] {}
            }
    }
    child {
        node[bag] {Bag 2}
            child {
                node[end] {}
            }
            child {
                node[end] {}
            }
    }
    child {
        node[bag] {Bag 2}
            child {% Here are three children, hence three end branches
                node[end] {}
            }
            child {
                node[end] {}
            }
            child {
                node[end] {}
            }
    };
\end{tikzpicture}

\end{document}

代码输出

相关内容