我该如何绘制这棵水平决策树?

我该如何绘制这棵水平决策树?

我正在尝试在 TeX 中编写以下决策树,但遇到了一些困难,尤其是对角箭头。

非常感谢您的建议或帮助!

在此处输入图片描述

答案1

我建议使用矢量图形程序,例如:Inkscape(开源)或 Adob​​e Illustrator(付费)。在那里创建您想要的绘图,然后将其包含在 LaTeX 中。

也许这可以帮助你:通过 TikZ 从 Inkscape 导出到 LaTeX

答案2

好吧,使用forest包可以简单地绘制:

\documentclass[border=3mm]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta,
                quotes}

\begin{document}
    \begin{forest}
for tree = {
% nodes
    draw,
    minimum width=3em,
    math content,
% tree
    grow'=0,
%    parent anchor=east,
%    child  
    anchor=west,
    s sep = 12mm,
    l sep = 12mm,
%
if level = 0{circle,fill, minimum size=0pt, inner sep=2pt}
            {parent anchor=east, child anchor=west},
% edge
    edge = {semithick,-Stealth},
% edge labels
ELA/.style= {edge label={node [pos=0.5, inner sep=2pt,
                              font=\scriptsize\sffamily, sloped,
                              above] {$#1$}}
            },
ELB/.style= {edge label={node [pos=0.5, inner sep=2pt,
                              font=\scriptsize, sloped,
                              below] {$#1$}}
           },
tier/.option=level,     % for aligning nodes to levels
            }% end for tree
[,
    [II, ELA=a
        [A
            [IP, name=a1
                [S_H, name=a2, ELA=p_I
                    [R_H, name=a3, ELA=\lambda+\delta]
                ]
            ]
        ]
        [NA]
    ]
    [NI, ELB=1-a,
        [NA
            [CP, name=b1
                [S_L, name=b2, ELB=1-p_c
                    [R_L, name=b3]
                ]
            ]
        ]
    ]
]
\tikzset{every edge/.style = {draw, -Stealth, semithick},
         every edge quotes/.style = {pos=0.7, auto, sloped, font=\scriptsize}
         }
\draw   (b1) edge ["$p_c$"]     (a2)
        (b2) edge ["$\delta$"]  (a3)
        (a1) edge ["$1-p_I$"]     (b2)
        (a2) edge ["$1-\lambda-\delta$"]  (b3);
   \end{forest}
\end{document}

在此处输入图片描述

相关内容