Drawing a graph using the PG 3.0 graphdrawing library

PGF 3.0 offers a new convenient and capable library for drawing graphs. The so called graphdrawin library requires compiling via LuaTeX.

The code was written by Mark Wibrow and published on TeX.SE.


drawing-graphs

Edit and compile if you like:

% Drawing a graph using the PG 3.0 graphdrawing library
% Author: Mark Wibrow
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}[>=stealth, every node/.style={circle, draw, minimum size=0.75cm}]
\graph [tree layout, grow=down, fresh nodes, level distance=0.5in, sibling distance=0.5in]
    {
        4 -> { 
          3 -> { 1 -> { 5, " " }, 2,2 },
          3 -> { 1, 2, 2 },
          3 -> { 1, 2, 2 }
        } 
    };
\end{tikzpicture}
\end{document}

Click to download: drawing-graphs.texdrawing-graphs.pdf
Open in Overleaf: drawing-graphs.tex