1

I have drawn the following right expanding tree graph in beamer, but its branches overlap each other. I have tried the sibling distance option but don't get the required results. Does anyone have an idea about how to do this correctly?.

enter image description here

My MWE is:

\begin{frame}  
\begin{tikzpicture}[->]  
\node {Start O}  
[grow=right]  
child{node{O}  
[grow=right]  
child{node{O}  
[grow=right]  
child{node{O}  
[grow=right]  
child{node[anchor=west]{O dead End}}  
child{node[anchor=west]{O Success Node}}  
}  
child{node{O}  
[grow=right]  
child{node{O}  
[grow=right]  
child{node{O}  
[grow=right]  
child{node{dead End}}  
}}}}  
child{node{O}  
[grow=right]  
child{node[anchor=west]{O dead End}}  
child{node[anchor=west]{O dead End}}  
child{node[anchor=west]{O dead End}}  
}  
}%-----------------------------  
child{node{O}}  
[grow = right]  
child{node[anchor=west]{dead End}}  
child{node{O}}  
[grow = right]  
child{node{O}  
[grow = right]  
child{node{O}  
[grow = right]  
child{node[anchor=west]{dead End}}}  
child{node[anchor=west]{dead End}}  
}  
child{node[anchor=west]{dead End}}  
;  
\end{tikzpicture}  
\end{frame}  
0

As I understand your tree, O is node, other text are labels. Than the tree drawing with plain tikz is:

enter image description here

\documentclass{beamer}
\usepackage{tikz}

\begin{document}
\begin{frame}
\centering
\begin{tikzpicture}[->,
every  node/.append style = {inner sep=1pt, anchor=west},
every label/.append style = {inner sep=0pt, font=\small},
grow=right,
level distance=11mm,
level 1/.style={sibling distance=28mm},
level 2/.style={sibling distance=14mm},
level 3/.style={sibling distance= 6mm},
level 4/.style={sibling distance= 4mm},
]
\node[label=left:Start, anchor=east] {O}
    % lover part
    child{node{O}
        child{node{O}
            child{node{O}
                child{node[label=right:Dead End]     {O}}
                child{node[label={[font=\bfseries]right:Success Node}] {O}}
                }
            child{node{O}
                child{node{O}
                    child{node{O}
                        child{node[label=right:Dead End] {O}}
                        }
                    }
                }
            }
        child{node{O}
            child{node[label=right:Dead End] {O}}
            child{node[label=right:Dead End] {O}}
            child{node[label=right:Dead End] {O}}
            }
        }
    % upper part
    child{node{O}
        child{node[label=right:Dead End] {O}}
        child{node{O}
            child{node{O}
                child{node{O}
                    child{node[label=right:Dead End] {O}}
                    }
                child{node[label=right:Dead End] {O}}
                }
            child{node[label=right:Dead End] {O}}
            }
        }
;
\end{tikzpicture}
\end{frame}
\end{document}

and with forest, where I assume, that nodes are circles:

enter image description here

\documentclass{beamer}
\usepackage{forest}

\begin{document}
\begin{frame}
\centering
    \begin{forest}
        for tree={
        % style of tree nodes
        circle, draw, inner sep=3pt,
        every label/.append style = {inner sep=0pt, font=\small},
        %
        grow=east,
        %child anchor=west, parent anchor=east,
        s sep = 2mm,    % sibling distance
    where level={1}{s sep=6mm}{},
    where level={2}{s sep=3mm}{},
        l sep = 9mm,    % level distance
         edge = {-latex},
        }
    [ , label=left:Start
        [ 
            [ 
                [ 
                    [ 
                        [ 
                            [ , label=right:Dead End]
                        ]
                    ]
                ]
                [ 
                    [ , label={[font=\bfseries]right:Sucess Node}]
                    [ , label=right:Dead End]
                ]
            ]
            [ 
                [ , label=right:Dead End]
                [ , label=right:Dead End]
                [ , label=right:Dead End]
            ]
        ]
        [ 
            [ 
                [ , label=right:Dead End]
                [ 
                    [ , label=right:Dead End]
                    [ 
                        [ , label=right:Dead End]
                    ]
                ]
            ]
            [ , label=right:Dead End]
        ]
    ]
    \end{forest}
\end{frame}
\end{document}
| improve this answer | |
3

Without many changes in your code, you can define a sibling distance per levelin the tikz options, to avoid the branches overlay. In addition, you can also define the global grow of the tree in the same options.

Output:

enter image description here

Code:

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}  
\begin{tikzpicture}[->,
grow=right,
level 1/.style={sibling distance=2.75cm,},
level 2/.style={sibling distance=1.45cm,},
level 3/.style={sibling distance=0.6cm,},
level 4/.style={sibling distance=0.4cm,},
]
\node {Start O}
    child{node{O}  
        child{node{O}  
            child{node{O}  
                child{node[anchor=west]{O dead End}}  
                child{node[anchor=west]{O Success Node}}  
            }  
        child{node{O}  
            child{node{O}  
                child{node{O}  
                    child{node{dead End}}  
        }}}}  
        child{node{O}  
            child{node[anchor=west]{O dead End}}  
            child{node[anchor=west]{O dead End}}  
            child{node[anchor=west]{O dead End}}  
        }  
    }%-----------------------------  
    child{node{O} 
        child{node[anchor=west]{dead End}}  
        child{node{O}  
            child{node{O}  
                child{node{O}  
                    child{node[anchor=west]{dead End}}}
                child{node[anchor=west]{dead End}}}  
            child{node[anchor=west]{dead End}}}  
    }
;  
\end{tikzpicture}  
\end{frame}
\end{document}

If it is not a problem for you, I recommend you to use the forest package, which is based on the tikz package, instead of solely the tikz package.

I hope there is no mistakes with the tree branches.

Output:

enter image description here

Code:

\documentclass{beamer}

\usepackage{forest}

\begin{document}
    \begin{frame}
        \begin{forest}
            for tree={% style of tree nodes
                grow=east,
                anchor=west, parent anchor=east,
                s sep = 2mm,    % sibling distance
                l sep = 8mm,   % level distance
                edge path={
                    \noexpand\path[\forestoption{edge},->, >={latex}]
                    (!u.parent anchor) -- (.child anchor)
                    \forestoption{edge label}; %edge/node connection
                },
            }
            [Start O
                [O
                    [O
                        [O
                            [O
                                [O
                                    [dead End]
                                ]
                            ]
                        ]
                        [O
                            [O Sucess Node]
                            [O dead End]
                        ]
                    ]
                    [O
                        [O dead End]
                        [O dead End]
                        [O dead End]
                    ]
                ]
                [O
                    [O
                        [dead End]
                        [O
                            [dead End]
                            [O
                                [dead End]
                            ]
                        ]
                    ]
                    [dead End]
                ]
            ]
        \end{forest}
    \end{frame}
\end{document}

There are a lot of possibilities to customize your tree with forest, see please the documentation.

A minimal change to improve the readability is changing the edge path, for example:

enter image description here

Code:

\documentclass{beamer}

\usepackage{forest}

\begin{document}
    \begin{frame}
        \begin{forest}
            for tree={% style of tree nodes
                grow=east,
                anchor=west, parent anchor=east,
                s sep = 2mm,    % sibling distance
                l sep = 8mm,   % level distance
                edge path={
                    \noexpand\path[\forestoption{edge},->, >={latex}]
                    (!u.parent anchor) -- +(5pt,0pt) |- (.child anchor)
                    \forestoption{edge label}; %edge/node connection
                },
            }
            [Start O
                [O
                    [O
                        [O
                            [O
                                [O
                                    [dead End]
                                ]
                            ]
                        ]
                        [O
                            [O Sucess Node]
                            [O dead End]
                        ]
                    ]
                    [O
                        [O dead End]
                        [O dead End]
                        [O dead End]
                    ]
                ]
                [O
                    [O
                        [dead End]
                        [O
                            [dead End]
                            [O
                                [dead End]
                            ]
                        ]
                    ]
                    [dead End]
                ]
            ]
        \end{forest}
    \end{frame}
\end{document}
| improve this answer | |
  • +1: Package forest seems very powerful. Your edge path option should be a possible standard option in the package. – Dr. Manuel Kuehner Jun 18 '19 at 20:38
  • i am using Miktex 2.9, and forest package is giving error "missing inserted for ifnum <to be read again> \requiredpackageexpl3 – awan Jun 19 '19 at 15:05
  • For me my MWE compiles with TeXLive 2019 as well as Miktex 2.9. Does the error appear with my MWE or when you have implemented my MWE in your code? Is your TeX distribution up to date? It seems to be related to a package that loads expl3. – Ñako Jun 19 '19 at 21:54

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.