Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 11 down vote accepted

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.

share|improve this answer
    
Thank you! Exactly what I needed. –  ravl1084 Nov 12 '11 at 0:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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