绘制多项处理树

绘制多项处理树

我是 LaTeX 的初学者,我想画一棵像图片中这样的树。我以前用 qtree 画过树,但从来没有画过这样的树。我知道我需要提供一些自己的代码,但我甚至不知道从哪里开始。谢谢!陣陣

答案1

(用于forest练习):

\documentclass[border=3mm]{standalone}
\usepackage[edges]{forest}

\begin{document}
    \begin{forest}
for tree = {
% nodes
    draw, 
    align=center,
    minimum height=5ex,
    minimum width=3em,
    font=\linespread{0.84}\selectfont,
% tree
    grow'=0,
    parent anchor=east,
    child  anchor=west,
    s sep = 4mm,    
    l sep = 12mm, 
% edge
    edge = {semithick},
% level styles
if level = 0{}{rounded corners=2ex},
where n children=0{tier=level, sharp corners}{calign=edge midpoint},
% edge labels
EL/.style={edge label={node [pos=0.5, fill=white,
                             font=\scriptsize\sffamily,
                             inner sep=2pt] {$#1$}}
                    }
            }% end for tree
[,coordinate
[target\\ item,no edge
    [recolection\\ certainity, EL=r
        ["yes"]
    ]
    [recolection\\ uncertainity, EL=1-r,
        [guess "yes", tier=L1, EL=g,
            ["yes"]
        ]
        [guess "no", tier=L1, EL=1-g
            ["no"]
        ]
    ]
]
[,coordinate, no edge]
[target\\ item, no edge
    [guess "yes", tier=L1, EL=g,
            ["yes"]
    ]
    [guess "no", tier=L1, EL=1-g
        ["no"]
    ]
 ]
]
    \end{forest}
\end{document}

在此处输入图片描述

答案2

为了好玩,以下是其中一棵树的解决方案pstricks

 \documentclass[border=26pt, svgnames]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{bigstrut}
\renewcommand{\bigstrutjot}{2.5ex}
\usepackage{ pst-tree}
\usepackage{auto-pst-pdf}

\newcommand*{\treebox}[1]{\setlength{\fboxrule}{0.8pt}\fcolorbox{SteelBlue}{LightSteelBlue!30}{\parbox{1.8cm}{\centering \color{DarkBlue} #1\strut}}}
\newcommand*{\treesmallbox}[1]{\setlength{\fboxrule}{0.8pt}\fcolorbox{SteelBlue}{LightSteelBlue!30}{\parbox{1cm}{\centering \color{DarkBlue} #1\strut}}}
\newcommand*{\treeovalbox}[2]{\psDefBoxNodes{#1}{\psframebox[framearc=1, linestyle=solid, linecolor=Crimson, fillstyle=solid, fillcolor=Thistle!20]{\parbox{2.2cm}{\centering #2\strut}}}}

\renewcommand{\psedge}{\ncline[nodesep=0pt]}

\begin{document}

\sffamily
\psset{treemode=R, treesep=1.2cm, levelsep=*2.4cm, linecolor=SteelBlue, linejoin=1}
\pstree{\Tr[name=T, ref=r, nodesepA=0pt]{\treebox{Target item\bigstrut}}}{%
\Tr[name=RC, ref=l]{\treeovalbox{Rc}{recollection\\certainty}}\ncput*{r}
        \pstree[linestyle=none]{\Tr[name=RU, ref=l]{\treeovalbox{Ru}{recollection\\ uncertainty}}\ncput*{1-r}\psset{linestyle =none}}{%
                \pstree[linestyle=solid, levelsep=2.2cm]{\Tr[name=GY, ref=r]{\treeovalbox{Gy}{guess 'yes' \bigstrut}}}{\Tr[name=Y]{\treesmallbox{ 'yes' }}}%
                \pstree[linestyle=solid, levelsep=2.2cm]{\Tr[name=GN, ref=r]{\treeovalbox{Gn}{guess 'no' \bigstrut}}\ncput*{1-g}}{\Tr[name=N]{\treesmallbox{ 'no' }}}%
        }%
        }%
        \ncline{Ru:Cr}{Gy:Cl}\ncput*{g}
        \ncline{Ru:Cr}{Gn:Cl}\ncput*{1-g}

\end{document} 

在此处输入图片描述

相关内容