# Dependency graph

> Course prerequisites as a directed acyclic graph, laid out in layers from left to right. A Graphs and networks example with its LaTeX source.

A Graphs and networks example in the TeXeR TikZ library: https://texer.org/library/graphs/dependency-dag

Package: [Graphs and networks](https://texer.org/library/graphs.md), on CTAN at https://ctan.org/pkg/pgf.

Tags: DAG, dependencies, topological order, prerequisites

## Source

```latex
\usetikzlibrary{arrows.meta}

\begin{tikzpicture}[
  >={Stealth},
  course/.style={draw, thick, rounded corners, text width=20mm, align=center, minimum height=9mm, font=\small},
]
  \node[course] (calc1) at (0,1.8) {Calculus I};
  \node[course] (linalg) at (0,0.6) {Linear algebra};
  \node[course] (prog) at (0,-0.6) {Programming};
  \node[course] (disc) at (0,-1.8) {Discrete math};
  \node[course] (calc2) at (3.1,1.8) {Calculus II};
  \node[course] (ds) at (3.1,-0.6) {Data structures};
  \node[course] (ode) at (6.2,1.2) {Differential equations};
  \node[course] (algo) at (6.2,-1.2) {Algorithms};
  \node[course] (ml) at (9.2,0) {Machine learning};

  \foreach \a/\b in {calc1/calc2, calc2/ode, linalg/ode, prog/ds, ds/algo, disc/algo, linalg/ml, algo/ml}
  \draw[->, thick] (\a.east) -- (\b.west);
\end{tikzpicture}
```

## As a complete document

The same example in a document that compiles on its own with pdfLaTeX:

```latex
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}[
  >={Stealth},
  course/.style={draw, thick, rounded corners, text width=20mm, align=center, minimum height=9mm, font=\small},
]
  \node[course] (calc1) at (0,1.8) {Calculus I};
  \node[course] (linalg) at (0,0.6) {Linear algebra};
  \node[course] (prog) at (0,-0.6) {Programming};
  \node[course] (disc) at (0,-1.8) {Discrete math};
  \node[course] (calc2) at (3.1,1.8) {Calculus II};
  \node[course] (ds) at (3.1,-0.6) {Data structures};
  \node[course] (ode) at (6.2,1.2) {Differential equations};
  \node[course] (algo) at (6.2,-1.2) {Algorithms};
  \node[course] (ml) at (9.2,0) {Machine learning};

  \foreach \a/\b in {calc1/calc2, calc2/ode, linalg/ode, prog/ds, ds/algo, disc/algo, linalg/ml, algo/ml}
  \draw[->, thick] (\a.east) -- (\b.west);
\end{tikzpicture}
\end{document}
```
