1

I am starting to use LaTeX for a graph theory course I am following at uni. I managed to build this tree, I am only missing the arrows (that should be pointing downwards in all of the edges).

\begin{tikzpicture}[level/.style={sibling distance=30mm/#1}]
\node [circle,draw] {1}
  child {node [circle,draw] {2}
    child {node [circle,draw] {5}}
    child {node [circle,draw] {6}}
    child {node [circle,draw] {7}}
  }
  child {node [circle,draw] {3}
  }
  child {node [circle,draw] {4}
    child {node [circle,draw] {8}}
    child {node [circle,draw] {9}}
    child {node [circle,draw] {10}}
};
\end{tikzpicture}

1 Answer 1

1

You only need to define style for edges:

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

\begin{document}
    \begin{tikzpicture}[
level/.style={sibling distance=30mm/#1},
edge from parent/.style={->,draw}   % <----
                        ]
\node [circle,draw] {1}
  child {node [circle,draw] {2}
    child {node [circle,draw] {5}}
    child {node [circle,draw] {6}}
    child {node [circle,draw] {7}}
  }
  child {node [circle,draw] {3}
  }
  child {node [circle,draw] {4}
    child {node [circle,draw] {8}}
    child {node [circle,draw] {9}}
    child {node [circle,draw] {10}}
};
\end{tikzpicture}
\end{document}

enter image description here

Similar result you can achieve by use of the package forest dedicated to drawing tree diagrams:

\documentclass[margin=3mm]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{forest}
for tree = {
    circle, draw, 
    minimum size=1.5em,
    inner sep=2pt,
%
    s sep=3mm,
    l sep=7mm,
    edge={-Straight Barb} % arrows head defined in 'arrows.meta'
            }
[1
    [2
        [5]
        [6]
        [7]
    ]
    [3,fit=band]
    [4
        [8]
        [9]
        [10]
    ]
r
]
    \end{forest}
\end{document}

enter image description here

2
  • Hi Zarko, thank you for your answer. I tried to put your code (copy/paste) from \begin{tikzpicture} till the end but my document does not compile. Maybe is due to my documentclass? I have \documentclass[12pt, tikz]{article} Commented Nov 8, 2020 at 9:50
  • I do not know, what you have in your document's preamble. There must be also loaded packages which are used in my examples (tikz at first, forest and used library arrows.meta at the second one). Otherwise, solution is independent from used document class.
    – Zarko
    Commented Nov 8, 2020 at 11:22

You must log in to answer this question.

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