1

I have the following decision tree I am trying to fit in one page. The output looks like the following. The MWE follows.

Note that as the tree grows to the fourth bottom node doses given it has 4 child nodes. This takes up too much space and is forced off the page. Another problem is that the path 7 node boxes overlap the boxes from the age node... (they are not the same! just a matter of geometry adding up).

I also have quite a bit of empty white space I'd like to fill up. In this sense, it would be nice to have 90 degree nodes rather than angled nodes.

mwe example

% Scenario tree
% Author: Rasmus Pank Roulund
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{amsmath}
\usepackage{xspace}
\begin{document}
\begin{tikzpicture}[
    grow=down,
    level 1/.style={sibling distance=6.3cm,level distance=3.5cm},
    edge from parent/.style={very thick,draw=black, %blue!40!black!60
        shorten >=5pt, shorten <=5pt},
    %edge from parent path={(\tikzparentnode.east) -- (\tikzchildnode.west)},
    kant/.style={text width=2cm, text centered, sloped},
    every node/.style={text ragged, inner sep=2mm},
    punkt/.style={rectangle, rounded corners, top color=white,
    bottom color=white, draw=black, very
    thick }
    ]
\node[punkt, text width=5.5em] {Health at infection}
    %Lower part lv1
    child {
        node[punkt] [rectangle split, rectangle split, rectangle split parts=3,
         text ragged] {
            \textbf{Path 6}
            \nodepart{second}
            $\mathcal{P}(\text{carriage}) = (0, 0)$
            \nodepart{third}
            $\mathcal{P}(\text{invasive}) = (0, 0)$
        }
        edge from parent
            node[kant, above] {Recovered}
    }
    %Upper part, lv1
    child {
        node[punkt] {previous infection?} 
        %child 1 %% "yes" child
        child {
            node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                \textbf{Path 7}
                \nodepart{second}
                $\mathcal{P}(\text{carriage}) = (0, 0)$
                \nodepart{third}
                $\mathcal{P}(\text{invasive}) = (0, 0)$
            }
            edge from parent
            node[below, kant] {Yes} % node[below, kant,  pos=.6] {Yes}
        }
        %child 2
        child {
            node [punkt]{is vaccinated?}
            child{
                node[punkt]{age}
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{ \textgreater{1825}} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{ \textless{1825}} 
                }
                edge from parent
                    node[kant, above]{No}
            } 
            child{
                node[punkt]{Doses Given}
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{1} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{2} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{3} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{4} 
                }
                edge from parent
                    node[kant, above]{Yes}
            } 
            edge from parent
                node[kant, above] {No}
        }
        edge from parent{
            node[kant, above] {From Susceptible}}
    };
\end{tikzpicture}
\end{document}

Kind of looking for something similar to the tree presented here: http://texample.net/tikz/examples/fault-tree/

1

I figured this out. Even though I have grow=down defined at a "global" level, I can redefine this at the node level. Now I have

enter image description here

with the code

% Scenario tree
% Author: Rasmus Pank Roulund
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{amsmath}
\usepackage{xspace}
\begin{document}
\begin{tikzpicture}[
    grow=down,
    level 1/.style={sibling distance=6.3cm,level distance=3.5cm},
    edge from parent/.style={very thick,draw=black, %blue!40!black!60
        shorten >=5pt, shorten <=5pt},
    %edge from parent path={(\tikzparentnode.east) -- (\tikzchildnode.west)},
    kant/.style={text centered, sloped}, %text width=2cm
    every node/.style={text ragged, inner sep=2mm},
    punkt/.style={rectangle, rounded corners, top color=white, bottom color=white, draw=black, very thick }
    ]
\node[punkt, text width=5.5em] {Health at infection}
    %Lower part lv1
    child {
        node[punkt] [rectangle split, rectangle split, rectangle split parts=3,
         text ragged] {
            \textbf{Path 6}
            \nodepart{second}
            $\mathcal{P}(\text{carriage}) = (0, 0)$
            \nodepart{third}
            $\mathcal{P}(\text{invasive}) = (0, 0)$
        }
        edge from parent
            node[kant, above] {recovered}
    }
    %Upper part, lv1
    child {
        node[punkt] {previous infection?} 
        %child 1 %% "yes" child
        child {
            node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                \textbf{Path 7}
                \nodepart{second}
                $\mathcal{P}(\text{carriage}) = (0, 0)$
                \nodepart{third}
                $\mathcal{P}(\text{invasive}) = (0, 0)$
            }
            edge from parent
            node[below, kant] {Yes} % node[below, kant,  pos=.6] {Yes}
        }
        %child 2
        child {
            node [punkt]{is vaccinated?}[grow=right]
            child{
                node[punkt]{Doses Given}[grow=down]
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{1} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{2} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{3} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{4} 
                }
                edge from parent
                    node[kant, above]{Yes}
            }
            child{
                node[punkt]{age}
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{ \textgreater{1825}} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{ \textless{1825}} 
                }
                edge from parent
                    node[kant, above]{No}
            }             
            edge from parent
                node[kant, above] {No}
        }
        edge from parent{
            node[kant, above] {From Susceptible}}
    };
\end{tikzpicture}
\end{document}
1

I had the same problem, and found the solution based on masfenix' solution code. However, I think my solution is simpler. Thus I'm going to add it, for those who google the same thing 2 years later, just like I did:

masfenix defined the following global variable in their tikzpicture: level 1/.style={sibling distance=6.3cm,level distance=3.5cm},

So, I thought, what if I try the same thing for each level, so I can set the distances for each level globally?

And, lo and behold, adding

level 2/.style={sibling distance=xy cm,level distance=xy cm},
level 3/.style={sibling distance=xy cm,level distance=xy cm},
and so on...

does what I want it to do. Success!

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.