编辑

编辑

如何在 LaTeX 中制作以下概率树?

谢谢您的帮助!!


概率树 1:

概率树 1

概率树2:

概率树 2

\forestset{my label/.style={if n=1{edge label={node [midway, above left, font=\tiny] {$#1$}},}{edge label={node [midway, below left, font=\tiny] {$#1$}},
}
}
}

\begin{forest}
for tree={
    grow'=0,
    math content,
    parent anchor=east,
    child anchor=west,
    edge path={
        \noexpand\path [\forestoption{edge}] (!u.parent anchor) node
        [circle, fill, minimum size=2.5pt, inner sep=0pt,
        anchor=center]
        {} -- (.child anchor)\forestoption{edge label};
        },
    edge={->},
    anchor=west,
    l sep+=15mm,
    s sep+=10mm,
}

%Left figure
[
   [\textbf{\textit{p}}^{good}, my label={P(good\rvert club_1)},
       tikz={\node (sa) [above=10mm of .north, anchor=base] {$S_A$};}]
   [\textbf{\textit{p}}_{rough}^{bad}, my label={P(bad\rvert club_1)}]
]


[, phantom, l sep-=25mm

%Right figure

[
[\textbf{\textit{p}}^{good}, my label={P(good\rvert club_2)},
   tikz={\node (sb) [anchor=base east] at (.west |- sa.base) {$S_B$};
   \draw [thick] (!r |- sa.south) -- (.east |- sa.south);}]

[\textbf{\textit{p}}^{bad}_{rough}, my label={P(bad\rvert club_2)}]
]
]
\end{forest}

概率树3:

概率树 3

答案1

这是最复杂的树。您应该能够对其进行修改以生成更简单的树。如果您遇到困难,只需发布​​您拥有的代码并询问如何解决您遇到的问题。

这使用了强大的forest包,允许使用标准括号符号来绘制树。我对先前问题的回答介绍forest并解释如何将树转换为括号规范。

\documentclass[tikz, border=10pt]{standalone}
\usepackage{forest,mathtools}
\usetikzlibrary{arrows.meta,positioning}% requires TikZ/PGF 3 - comment if you don't have arrows.meta
%\usetikzlibrary{positioning}% uncomment if you don't have arrows.meta
\begin{document}
\forestset{
  my label/.style={
    if n=1{
      edge label={node [midway, above left, font=\tiny] {$#1$}},
    }{
      edge label={node [midway, below left, font=\tiny] {$#1$}},
    }
  }
}
\begin{forest}
  for tree={
    grow'=0,
    math content,
    parent anchor=east,
    child anchor=west,
    edge path={
      \noexpand\path [\forestoption{edge}] (!u.parent anchor) node [circle, fill, minimum size=2.5pt, inner sep=0pt, anchor=center] {} -- (.child anchor)\forestoption{edge label};
    },
    edge={-{Stealth[]}},% requires TikZ/PGF version 3 - comment if you don't have arrows.meta
    %edge={->},% uncomment this line if you don't have arrows.meta
    anchor=west,
    l sep+=15mm,
    s sep+=5mm,
  }
  [
    [p^{good}, my label={P[good\rvert club_1]}, tikz={\node (sa) [above=10mm of .north, anchor=base] {$S_A$};}
    ]
    [p^{bad}, my label={P[bad\rvert club_1]}
      [p^{bad}_{rough}, my label={\delta\cdot P[bad\rvert club_1]}
        [, phantom, l sep-=25mm
          [
            [p^{good}, my label={P[good\rvert club_2]},
              tikz={
                \node (sb) [anchor=base east] at (.west |- sa.base) {$S_B$};
                \draw [thick] (!r |- sa.south) -- (.east |- sa.south);
              }
            ]
            [p^{bad}_{rough}, my label={P[bad\rvert club_2]}
            ]
          ]
        ]
      ]
      [p^{bad}_{sand}, my label={(1-\delta)\cdot P[bad\rvert club_1]}
      ]
    ]
  ]
\end{forest}
\end{document}

概率树

编辑

以下是有关这三棵树的一些帮助:

\documentclass[tikz, border=10pt, multi]{standalone}
\usepackage{forest,mathtools}
\usetikzlibrary{arrows.meta,positioning}
\begin{document}
\forestset{
  my label/.style={
    if n=1{
      edge label={node [midway, above left, font=\tiny] {$#1$}},
    }{
      edge label={node [midway, below left, font=\tiny] {$#1$}},
    }
  }
}

\begin{forest}
  for tree={
    grow'=0,
    math content,
    parent anchor=east,
    child anchor=west,
    edge path={
      \noexpand\path [\forestoption{edge}] (!u.parent anchor) node [circle, fill, minimum size=2.5pt, inner sep=0pt, anchor=center] {} -- (.child anchor)\forestoption{edge label};
    },
    edge={-{Stealth[]}},
    anchor=west,
    l sep+=15mm,
    s sep+=5mm,
    if level=1{tier=t}{}
  }
  [
  [p^{bad}_{O.B.}, tikz={\node (sa) [above=10mm of .north, anchor=base east] {$unplayable$};}
    ]
    [, phantom
      [,
        [p^{bad}_{rough},
          tikz={
            \node (sb) [anchor=base east] at (.center |- sa.base) {$playable$};
            \draw [thick] (!r |- sa.south) -- (.east |- sa.south);
          }
        ]
        [p^{bad}_{trees}]
        [p^{bad}_{sand}
        ]
      ]
    ]
    [p^{bad}_{water}
    ]
  ]
\end{forest}
\begin{forest}
  for tree={
    grow'=0,
    math content,
    parent anchor=east,
    child anchor=west,
    edge path={
      \noexpand\path [\forestoption{edge}] (!u.parent anchor) node [circle, fill, minimum size=2.5pt, inner sep=0pt, anchor=center] {} -- (.child anchor)\forestoption{edge label};
    },
    edge={-{Stealth[]}},
    anchor=west,
    l sep+=15mm,
    s sep+=5mm,
    if level=1{tier=t}{}
  }
  [
    [p^{good}, my label={P[good\rvert club_1]}, tikz={\node (sa) [above=10mm of .north, anchor=base] {$S_A$};}
    ]
    [, phantom
      [,
        [p^{good}, my label={P[good\rvert club_2]},
          tikz={
            \node (sb) [anchor=base east] at (.west |- sa.base) {$S_B$};
            \draw [thick] (!r |- sa.south) -- (.east |- sa.south);
          }
        ]
        [,phantom]
        [p^{bad}_{rough}, my label={P[bad\rvert club_2]}
        ]
      ]
    ]
    [p^{bad}_{rough}, my label={P[bad\rvert club_1]}
    ]
  ]
\end{forest}
\begin{forest}
  for tree={
    grow'=0,
    math content,
    parent anchor=east,
    child anchor=west,
    edge path={
      \noexpand\path [\forestoption{edge}] (!u.parent anchor) node [circle, fill, minimum size=2.5pt, inner sep=0pt, anchor=center] {} -- (.child anchor)\forestoption{edge label};
    },
    edge={-{Stealth[]}},
    anchor=west,
    l sep+=15mm,
    s sep+=5mm,
  }
  [
    [p^{good}, my label={P[good\rvert club_1]}, tikz={\node (sa) [above=10mm of .north, anchor=base] {$S_A$};}
    ]
    [p^{bad}, my label={P[bad\rvert club_1]}
      [p^{bad}_{rough}, my label={\delta\cdot P[bad\rvert club_1]}
        [, phantom, l sep-=25mm
          [
            [p^{good}, my label={P[good\rvert club_2]},
              tikz={
                \node (sb) [anchor=base east] at (.west |- sa.base) {$S_B$};
                \draw [thick] (!r |- sa.south) -- (.east |- sa.south);
              }
            ]
            [p^{bad}_{rough}, my label={P[bad\rvert club_2]}
            ]
          ]
        ]
      ]
      [p^{bad}_{sand}, my label={(1-\delta)\cdot P[bad\rvert club_1]}
      ]
    ]
  ]
\end{forest}
\end{document}

三棵树

看看我上面链接的答案,以帮助您理解括号符号。否则,这看起来只是魔术,您不可能适应 ;)。

相关内容