0

I am extremely beginner at LaTeX and I want to draw a tree like the one in the picture. I previously draw trees using qtree but I never did a tree like this. I know I need to provide my own code a bit, but I do not even know where to start. Thank you! mpt

  • 2
    There are plenty of examples of this sort of tree on the site. I would recommend forest over qtree or tikz-qtree for most trees these days. – Alan Munn Nov 27 '19 at 15:06
1

With forest (for exercise):

\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}

enter image description here

| improve this answer | |
  • This is what I was looking for thank you so much! – Utku Türk Dec 2 '19 at 10:19
1

For fun, a solution for one of these trees with 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} 

enter image description here

| improve this answer | |
  • Wow this is really nice, I need to use black and white one, but I wish my journal would accept something like this! – Utku Türk Dec 2 '19 at 10:19
  • 1
    You can make it black and white easily: just remove, in the keys, all fillstyle=solid, \fillcolor= …, linecolor= …. – Bernard Dec 2 '19 at 10:43
  • Thank you! I never used pstricks before. Do you think it is better than forest? – Utku Türk Dec 2 '19 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.