9

I am trying to draw a decision tree. I have gotten very close to the end result with this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees,shapes,snakes}
\begin{document}
\tikzstyle{level 1}=[level distance=1.5cm, sibling distance=2.5cm]
\tikzstyle{level 2}=[level distance=1cm, sibling distance=2cm]
\tikzstyle{level 3}=[level distance=1cm, sibling distance=1.5cm]
\tikzstyle{bag} = [rectangle, text width=4em, text centered, draw]
\tikzstyle{decision} = [rectangle, minimum height=8pt, minimum width=8pt, fill, inner sep=0pt]
\tikzstyle{choice} = [circle, minimum width=8pt, fill, inner sep=0pt]
\tikzstyle{end} = [regular polygon, regular polygon sides=3, minimum width=8pt, fill, inner sep=0pt]

\begin{tikzpicture}[grow=right,child anchor=west]
\tiny
\node[bag]{Decision}
child {
    node[decision]{}
    child {
        node[bag]{Option 1}
            child{
                node[choice]{}
                child {
                    node[bag]{Outcome 1}
                    child {
                        node[end]{}
                    }
                }
                child {
                    node[bag]{Outcome 2}
                    child {
                        node[end]{}
                    }
                }
            }
    }
    child {
        node[bag]{Option 2}
            child{
                node[choice]{}
                child {
                    node[bag]{Outcome 3}
                    child {
                        node[end]{}
                    }
                }
                child {
                    node[bag]{Outcome 4}
                    child {
                        node[end]{}
                    }
                }
            }
        }
    };
\end{tikzpicture}
\end{document}

The only issue I'm having is that I cannot find a way to rotate the last node (end), shaped as a triangle, as it should point towards its parent, not upwards. Any ideas?

12

You can rotate the end nodes by using the option shape border rotate=90 (unlike rotate=90, this will not shift the anchor point used by the tree, so the shape will be correctly aligned).

This will leave a small gap between the tip of the triangle and the edge of the tree. To avoid this, you can set outer sep=-\pgflinewidth, which will move the anchor slightly inside the shape, so the edge of the tree and the triangle overlap.

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.