\documentclass[a4paper,fontsize=12pt,listof=totoc,toc=sectionentrywithdots]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{emoji}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\usepackage{lmodern}
\usepackage[onehalfspacing]{setspace}
\setcounter{secnumdepth}{5} % numbered paragraphs
\usepackage{fancyhdr}
    \setlength{\headheight}{15.2pt}
    \pagestyle{fancy}
    \fancyhf{}
    \fancyhead[R]{\leftmark}
    \fancyhead[L]{Tikz Graphs}
    \fancyfoot[C]{\thepage}

%
% tikz
%

\usepackage{tikz}
\usepackage{tikzsymbols}
\usetikzlibrary{trees, graphs, graphdrawing, automata, positioning, quotes, arrows}
\usegdlibrary{force, trees, circular, layered} % choosing look of graphs

%
% define custom colors
%

\definecolor{bmpink}{HTML}{FF91AF}
\definecolor{mauve}{HTML}{BB85AB}
\definecolor{pastyel}{HTML}{FFFFCA}

%
% math packages
%

\usepackage{mathtools}
\usepackage{amsxtra,amssymb,amsthm,amstext,amsfonts}
\usepackage{esint} % for circle integrals

%
% microtype setting
%

\usepackage{float} % better control of placements
\usepackage{microtype} % package for optimising typographic details

%
% tables
%

\usepackage{booktabs} % optimised display of tables
\usepackage{tabularx} % more modern display of tables with \toprule,\midrule,\bottomrule
\usepackage{multirow} % allows table cells over multiple rows within a column

%
% misc packages
%

\usepackage[extendedchars]{grffile} % for spaces and special chars in file paths
\usepackage{xcolor} % adds colours
\usepackage{multicol} % allows dividing (parts of) the page into multiple columns
\usepackage[hyphens]{url} % adds hyperlinks
\usepackage[]{hyperref} % adds links to toc

%
% math related custom commands
%

\renewcommand{\epsilon}{\varepsilon}
\renewcommand{\phi}{\varphi}
\newtheorem{lemma}{Lemma}

%
% maketitle
%

\title{Tikz Graphs}
\subject{cheat sheet}
\author{Isabell Pflug}
\date{\today}

%
% document
%

\begin{document}
\maketitle
\tableofcontents

%
% Trees
%

\pagebreak
\section{Trees}
\begin{center}
    \begin{tikzpicture}[level distance=1.5cm, level 1/.style={sibling distance=2cm}, node distance={2cm}, thick, main/.style = {draw, circle}]
        \node (start) {};
        \node[main] (a) [below of = start, node distance = {0.7cm}] {a}
            child { node[main] (b) {b} }
            child { node[main] (c) {c} }
            child { node[main] (d) {d}
                child { node[main] (e) {e} } };
        \node[main, draw=none] (h) [right of = a] {};
        \node[main] (f) [right of = h] {f}
            child { node[main] (g) {g} };
    \end{tikzpicture}
\end{center}

%
% Graph section
%

\pagebreak
\section{Graphs}

%
% Simple Necklace Layout
%

\subsection{Simple Necklace Layout}
\begin{tikzpicture}[inner sep=2pt]
    \graph [simple necklace layout, node distance=1cm, nodes={circle, draw, minimum size=0.4cm}, empty nodes]
    {
        $G$ // { 1[x=1,y=2], 2, 3, 4, 5,
            1 --[red] 3 --[red] 5 --[red] 2 --[red] 4 --[red] 1
        }
    };
    \graph [simple necklace layout, node distance=1cm, nodes={circle, draw, minimum size=0.4cm}, empty nodes]
    {
        $G^{C}$ // { 1[x=4,y=2], 2, 3, 4, 5,
            1 --[green] 2 --[green] 3 --[green] 4 --[green] 5 --[green] 1
        }
    };
    \graph [simple necklace layout, node distance=1cm, nodes={circle, draw, minimum size=0.4cm}, empty nodes]
    {
        $K_{5}$ // { 1[x=7,y=2], 2, 3, 4, 5,
            1 --[green] 2 --[green] 3 --[green] 4 --[green] 5 --[green] 1,
            1 --[red] 3 --[red] 5 --[red] 2 --[red] 4 --[red] 1
        }
    };
\end{tikzpicture} \\
\begin{tikzpicture}[inner sep=2pt]
    \centering
    \graph [simple necklace layout, node distance=1cm, nodes={circle, draw, minimum size=0.4cm}, empty nodes]
    { 
        $K_{4}$ // { 1[fill=bmpink, x=1,y=2], 2[fill=pastyel], 3[fill=mauve], 4[fill=bmpink], 3 -- 1 -- 2 -- 3 -- 4 -- 2, 1 -- 4 }
    };
    \graph [simple necklace layout, node distance=1cm, nodes={circle, draw, minimum size=0.4cm}, empty nodes]
    {
        $H$ // { 1[fill=bmpink, x=4,y=2], 2[fill=pastyel], 3[fill=mauve], 4[fill=bmpink], 5[fill=mauve], 6[fill=pastyel], 1 -- 2 -- 3 -- 1,
        2 -- 4 -- 3, 2 -- 5,
        3 -- 6,
        5 -- 4 -- 6 -- 5,
        4,
        6 -- 1 -- 5 
        }
    };
\end{tikzpicture}

%
% Spring Layout
%

\subsection{Spring Layout, weighted edges}
\begin{center}
\begin{tikzpicture}[inner sep=2pt, thick]
\graph [spring layout, node distance=1cm, nodes={circle, draw, minimum size=0.6cm}]
    { 
        A[x=1,y=6] --[bmpink] B[x=5,y=6] ->[bmpink] C[x=3.5,y=4] -- A,
        A -- E[x=1,y=2] -- C,
        B --[bmpink] D[x=9,y=6] --[bmpink] F[x=6.5,y=4] -- C,
        E --[bmpink] G[x=9,y=2] --[bmpink] D,
        F -- G
    };
\path (A) edge[draw = none] node[anchor = south] {$5$} (B);
\path (B) edge[draw = none] node[anchor = south] {$14$} (D);
\path (B) edge[draw = none] node[anchor = south east] {$2$} (C);
\path (A) edge[draw = none] node[anchor = east] {$22$} (E);
\path (E) edge[draw = none] node[anchor = south east] {$20$} (C);
\path (C) edge[draw = none] node[anchor = south] {$16$} (F);
\path (F) edge[draw = none] node[anchor = south west] {$12$} (G);
\path (E) edge[draw = none] node[anchor = south] {$7$} (G);
\path (D) edge[draw = none] node[anchor = west] {$4$} (G);
\path (F) edge[draw = none] node[anchor = south east] {$10$} (D);
\path (A) edge[draw = none] node[anchor = south west] {$8$} (C);

\end{tikzpicture}
\end{center}

\subsection{Layered Layout}
\subsubsection{Bipartite}
\begin{center}
\begin{tikzpicture}[inner sep=2pt, thick]
\graph [layered layout, nodes={circle, draw, minimum size=0.6cm}, sibling distance=5cm, level distance=5cm]%, grow=-80]
  {
    {a,b,c} --[complete bipartite, bmpink] {e,d,f}
            --[complete bipartite] {g,h,i};
  };
\end{tikzpicture}
\end{center}

%
% Automatons
%

\pagebreak
\section{Automatons}
\begin{tikzpicture}[every initial by arrow/.style={->>,thick}]

  \node[state,initial]  (q_0)                      {$q_0$};
  \node[state, accepting]          (q_1) [above right=of q_0] {$q_1$};
  \node[state]          (q_2) [below right=of q_0] {$q_2$};
  \node[state, accepting]          (q_3) [right=of q_2] {$q_3$};

  \path[->, thick] (q_0) edge                                 node [above left]   {0} (q_1)
                  edge                                 node [below left]   {1} (q_2)
            (q_1) edge [loop above]                    node                {0} ()
            (q_2) edge [loop below]                    node                {1} ()
            (q_3) edge [bend right=22,looseness=0.8]   node [above]        {0} (q_2)
            (q_2) edge [bend right=22,looseness=0.8]   node [below]        {0} (q_3);
\end{tikzpicture}

\end{document}
