Creating Elegant Graph Visualizations with TikZ: From Simple Networks to Complex Structures

Graph theory visualizations are essential for understanding network structures, algorithms, and mathematical relationships. In this post, I'll walk through how to create professional-looking graph diagrams using LaTeX and TikZ, progressing from a simple 5-node graph to more complex structures.

The Power of TikZ for Graph Drawing

TikZ is a powerful package for creating graphics programmatically in LaTeX. When it comes to drawing graphs and networks, TikZ offers precise control over node positioning, edge styling, and visual effects that make your diagrams publication-ready.

\usepackage{tikz}
\usetikzlibrary{shadows}

\begin{center}
    \begin{tikzpicture}[-, thick]
        \tikzstyle{b2}=[circle,fill=black,draw=none,drop shadow,text=white,text centered,minimum height=0.75cm,node distance=2.5cm,scale=0.5]
        \node[b2] (V1) {$V_{1}$};
        \node[b2] (V2) [below right of = V1] {$V_{2}$};
        \node[b2] (V3) [below of = V2] {$V_{3}$};
        \node[b2] (V5) [below left of = V1] {$V_{5}$};
        \node[b2] (V4) [below of = V5] {$V_{4}$};
        \draw[-]  (V1) -- (V2);
        \draw[-]  (V1) -- (V5);
        \draw[-]  (V1) -- (V4);
        \draw[-]  (V2) -- (V3);
        \draw[-]  (V3) -- (V5);
        \draw[-]  (V5) -- (V4);
    \end{tikzpicture}
\end{center}

\begin{center}
    \begin{tikzpicture}[-, thick]
        \tikzstyle{b2}=[circle,fill=black,draw=none,text=white,text centered,minimum height=0.75cm,node distance=2cm,scale=0.4]
        \node[b2] (V1) {};
        \node[b2] (V2) [right of = V1] {};
        \node[b2] (V3) [right of = V2] {};
        \node[b2] (V4) [below of = V1] {};
        \node[b2] (V5) [right of = V4] {};
        \node[b2] (V6) [right of = V5] {};

        \draw[-]  (V1) -- (V4);
        \draw[-]  (V1) -- (V5);
        \draw[-]  (V2) -- (V3);
        \draw[-]  (V2) -- (V4);
        \draw[-]  (V2) -- (V5);
        \draw[-]  (V5) -- (V6);

        \path[-] (V1) edge [bend left] (V3)
        (V4) edge [bend right] (V6);
    \end{tikzpicture}
\end{center}

\begin{center}
    \begin{tikzpicture}[-, thick]
        \tikzstyle{b2}=[circle,fill=black,draw=none,text=white,text centered,minimum height=0.75cm,node distance=2.5cm,scale=0.4]
        \node[b2] (V1) {};
        \node[b2] (V2) [right of = V1] {};
        \node[b2] (V3) [right of = V2] {};
        \node[b2] (V4) [below of = V1] {};
        \node[b2] (V5) [right of = V4] {};
        \node[b2] (V6) [right of = V5] {};
        \node[b2] (V7) [below of = V4] {};
        \node[b2] (V8) [right of = V7] {};
        \node[b2] (V9) [right of = V8] {};

        \draw[-]  (V1) -- (V2);
        \draw[-]  (V2) -- (V3);
        \draw[-]  (V1) -- (V4);
        \draw[-]  (V2) -- (V5);
        \draw[-]  (V3) -- (V6);
        \draw[-]  (V4) -- (V5);
        \draw[-]  (V5) -- (V6);
        \draw[-]  (V6) -- (V9);
        \draw[-]  (V7) -- (V8);
        \draw[-]  (V8) -- (V9);
        \draw[-]  (V4) -- (V7);
        \draw[-]  (V5) -- (V8);

        \path[-] (V1) edge [bend left] (V3)
        (V4) edge [bend left] (V6)
        (V7) edge [bend left] (V9);
    \end{tikzpicture}
\end{center}

First Graph: A 5-Node Network with Shadows

The first example demonstrates a simple yet visually appealing graph with five vertices. What makes this diagram stand out is the use of drop shadows, which adds depth and makes the nodes appear to float above the page.

Key Implementation Details

The node style is defined using \tikzstyle:

\tikzstyle{b2}=[circle,fill=black,draw=none,drop shadow,text=white,text centered,minimum height=0.75cm,node distance=2.5cm,scale=0.5]

Breaking down this style definition:

  • circle: Creates circular nodes

  • fill=black: Fills nodes with black colour

  • draw=none: Removes the border outline

  • drop shadow: The crucial element that adds depth

  • text=white: Makes vertex labels visible against black background

  • text centered: Centres the labels within nodes

  • minimum height=0.75cm: Ensures consistent node sizes

  • node distance=2.5cm: Sets default spacing between nodes

The Shadow Effect

To enable the drop shadow effect, you need to include the shadows library at the beginning of your document:

\usetikzlibrary{shadows}

This library provides the drop shadow option, which automatically creates a subtle shadow beneath each node, giving the graph a three-dimensional appearance. The shadow effect is particularly effective when you want to emphasize the nodes as the primary elements of your visualization.

Node Positioning

The graph uses relative positioning with commands like:

  • below right of = V1: Places a node below and to the right

  • below of = V2: Places a node directly below

  • below left of = V1: Places a node below and to the left

This approach creates a balanced, symmetric layout without requiring manual coordinate calculations.

Second Graph: A 6-Node Bipartite-Style Layout

The second graph removes the shadows and vertex labels, creating a cleaner, more minimalist appearance. This graph introduces curved edges using the bend option:

\path[-] (V1) edge [bend left] (V3)
        (V4) edge [bend right] (V6);

The bend left and bend right options create smooth curves that help avoid edge crossings and improve readability. This is particularly useful when connecting non-adjacent nodes in a structured layout.

Third Graph: A 9-Node Grid Structure

The final graph scales up to nine nodes arranged in a 3×3 grid pattern. This demonstrates how the same styling approach scales to larger networks. The graph combines straight edges for adjacent connections with curved edges for diagonal connections:

\path[-] (V1) edge [bend left] (V3)
        (V4) edge [bend left] (V6)
        (V7) edge [bend left] (V9);

Best Practices and Tips

  1. Consistent Styling: Define your node style once and reuse it throughout the diagram for consistency.

  2. Relative Positioning: Use TikZ's relative positioning options (above of, right of, etc.) instead of absolute coordinates for easier maintenance and modification.

  3. Visual Hierarchy: The first graph uses shadows and labels to emphasize importance, while the later graphs use a cleaner style for structural clarity.

  4. Edge Variations: Combine straight edges for direct connections with curved edges for long-distance connections to improve visual flow.

  5. Scaling: The scale parameter in the node style allows you to adjust node sizes without changing the overall graph structure.

Conclusion

TikZ provides a powerful framework for creating publication-quality graph visualizations in LaTeX. By combining basic elements like nodes and edges with advanced features like shadows and curved paths, you can create diagrams that are both informative and visually appealing. The progression from the shadowed, labelled graph to the minimal grid structure shows how the same fundamental techniques can be adapted to different visualization needs.

Whether you're illustrating network algorithms, social networks, or mathematical concepts, these TikZ techniques will help you create clear, professional diagrams that enhance your academic or technical documents.

0
Subscribe to my newsletter

Read articles from Amirkiarash Kiani directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Amirkiarash Kiani
Amirkiarash Kiani

LaTeX enthusiastic. Beginner Ubuntu use and web developer.