1

I am trying to draw a simple decision tree like in Figure 1 of https://besjournals.onlinelibrary.wiley.com/doi/full/10.1111/j.1365-2656.2008.01390.x

Unfortunately whatever I try, I cant adjust the sibling distance for the first branch. I am quite new to tikz so every help is appreciated. Minimal working code example:

\documentclass{minimal}
\usepackage[a4paper,margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows,arrows}
\begin{document}
\begin{center}
\begin{tikzpicture}[
    fact/.style={rectangle, draw=blue, rounded corners=1mm, fill=white, %drop shadow,
        text centered, anchor=north, text=black},
    state/.style={circle, draw=orange, fill=white, %circular drop shadow,
        text centered, anchor=north, text=black},
    leaf/.style={circle, draw=red, fill=white, %circular drop shadow,
        text centered, anchor=north, text=black},
    level distance=1cm, growth parent anchor=south,
]
\node (State00) [state] {$x_{1}$}
child{ 
    node (Fact01) [fact] {$\leq z_1$}
    child{ [sibling distance=4cm]
        node (State01) [state] {$x_2$} 
        child{ 
            node (Fact02) [fact] {$\leq z_1$}
            child{ [sibling distance=2cm]
                node (State02) [leaf] {$y_1$}
                }
            }       
        child{
            node (Fact03) [fact] {$> z_1$}
            child{
                node (State03) [leaf] {$y_2$}
                }
            }
        }
    node (Fact04) [fact] {$> z_1$}
    child{ [sibling distance=3cm]
        node (State04) [state] {$x_1$}
        child{ 
            node (Fact05) [fact] {$\leq z_3$}
            child{
                node (State05) [leaf] {$y_3$} 
                }
            }
        child{
            node (Fact06) [fact] {$> z_3$}
            child{ [sibling distance=3cm]
                node (State06) [state] {$x_2$}
                child{
                    node (Fact07) [fact] {$\leq z_4$}
                    child{ 
                        node (State07) [leaf] {$y_4$}
                        }
                    }
                child{
                    node (Fact08) [fact] {$> z_4$}
                    child{
                        node (State08) [leaf] {$y_5$}
                        }
                    }
                }
            }
        }
    }
;

\end{tikzpicture}
\end{center}
\end{document}

my Output always looks like this:

enter image description here

1

I suspect that you look for the following tree diagram:

enter image description here

I must confess that i went lost in your code. SO I sugest (to my opinion) to simple solution using forest package:

\documentclass[tikz,margin=3mm]{standalone}
\usepackage{forest}

\begin{document}
\begin{forest}
for tree = {
fact/.style={rectangle, draw=blue, rounded corners=1mm,
             text centered, text=black},
        circle, 
        draw=orange, 
        text centered, 
        text=black,
        s sep+=4pt,
        l sep=8mm
            }
[$x_1$
    [$\leq z_1$,fact
        [$x_1$
            [$\leq z_1$,fact
                [$y_1$]
            ]
            [$\leq z_2$,fact
                [$y_2$]
            ]
            [$>z_3$,fact
                [$x_2$
                    [$\leq z_4$,fact
                        [$y_4$]
                    ]
                    [$>z_4$,fact
                        [$y_5$]
                    ]
                ]
            ]
            [$>z_1$,fact
                [$y_5$]
            ]
        ]
    ]
]
;
\end{forest}
\end{document}
  • thanks, thats not exactly the graph I was looking, but the forest package got me there! As I said I am new to drawing graphs in Latex and I only found that confusing syntax to draw decision trees. I was looking for a way to have a split right at the beginning and thats easily doable with forest :) – Quastiat Aug 27 at 15:25
  • @Quastiat, to clarify, how the three look like, please add sketch of it to answer. From presented result of your code (which I didn't succeed to replicate) I figured out what I show in answer :-( – Zarko Aug 27 at 15:40
  • nevermind your answer helped me perfectly. The issues was trying the draw my tree with tikzpicture, that was very unconvenient. My Graph had two overlapping child nodes at the beginning, but thats solved now :) – Quastiat Aug 27 at 16:07
  • I suggest you take a look at the pst-tree module of pstricks. – Bernard Aug 27 at 17:03

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.