3

I am trying to build this decision tree I was take out fill option at

\tikzstyle{choice} = [circle, minimum width=8pt, fill, inner sep=0pt]

and also make the tree grow down

\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} = [circle, 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} = [circle, text width=1em, text centered, draw, inner sep=0pt]

\begin{tikzpicture}[grow=right, child anchor=west]
\tiny
\node[bag]{XOR}
child {
    node[decision]{TEST}
    child {
        node[bag]{A= 0}
            child{
                node[choice]{}
                child {
                    node[bag]{B=0}
                    child {
                        node[end]{0}
                    }
                }
                child {
                    node[bag]{B=1}
                    child {
                        node[end]{1}
                    }
                }
            }
    }
    child {
        node[bag]{A=1}
            child{
                node[choice]{}
                child {
                    node[bag]{B=0}
                    child {
                        node[end]{1}
                    }
                }
                child {
                    node[bag]{B=1}
                    child {
                        node[end]{0}
                    }
                }
            }
        }
    };

\end{tikzpicture}
3
  • 2
    Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. With a few more lines you can make this example fully compilable by copy/pasting :)
    – percusse
    Commented Oct 3, 2012 at 12:52
  • I don't quite understand what you are asking. The default behaviour is for the tree to grow down. You can make it grow "west" instead with the grow=left option.
    – Seamus
    Commented Oct 3, 2012 at 13:05
  • My tree grows side ways i want to grow it downwards natural progression, i am very new to latex Commented Oct 3, 2012 at 13:13

1 Answer 1

5

If you don't give any options, the tree grows downwards, naturally. I have changed

\tikzstyle{decision} = [rectangle, minimum height=8pt, minimum width=8pt, fill, inner sep=0pt]

to

\tikzstyle{choice} = [circle, minimum width=8pt, draw, inner sep=0pt]

to remove the fill. Also you have to use appropriate distances in

\tikzstyle{level 2}=[level distance=1cm, sibling distance=5cm]

so that things don't overlap.

Your code becomes

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzstyle{level 1}=[level distance=1.5cm, sibling distance=2.5cm]
\tikzstyle{level 2}=[level distance=1cm, sibling distance=5cm]
\tikzstyle{level 3}=[level distance=1cm, sibling distance=2cm]
\tikzstyle{bag} = [circle, 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, draw, inner sep=0pt]
\tikzstyle{end} = [circle, text width=1em, text centered, draw, inner sep=0pt]

\begin{tikzpicture}%%[grow=left, child anchor=east]
\tiny
\node[bag]{XOR}
child {
    node[decision]{TEST}
    child {
        node[bag]{A= 0}
            child{
                node[choice]{}
                child {
                    node[bag]{B=0}
                    child {
                        node[end]{0}
                    }
                }
                child {
                    node[bag]{B=1}
                    child {
                        node[end]{1}
                    }
                }
            }
    }
    child {
        node[bag]{A=1}
            child{
                node[choice]{}
                child {
                    node[bag]{B=0}
                    child {
                        node[end]{1}
                    }
                }
                child {
                    node[bag]{B=1}
                    child {
                        node[end]{0}
                    }
                }
            }
        }
    };

\end{tikzpicture}
\end{document}

enter image description here

Hope that helps!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .