Chapter 4 – Drawing Edges

Here are the Code examples of this chapter. You can compile them online right on this web page by pressing the Typeset / Compile button. You can also edit them for testing, and compile again.

For a better view with the online compiler, I use \documentclass[border=10pt]{standalone} instead of \documentclass{article}. Instead of having a big letter/A4 page, the standalone class crops the paper to see just the visible text without an empty rest of a page.

Any question about a code example? Post it on LaTeX.org, I will answer. As forum admin I read every single question there. (profile link).

Basic edge

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
  \node (tex) [fill=orange, text=white] {TEX};
  \node (pdf) [fill={rgb:red,244;green,15;blue,2},
    text=white, right=of tex] {PDF};
  \draw (tex) edge[->] (pdf);
\end{tikzpicture}
\end{document}

With text over the edge:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
  \node (tex) [fill=orange, text=white] {TEX};
  \node (pdf) [fill={rgb:red,244;green,15;blue,2},
    text=white, right=of tex] {PDF};
  \draw (tex) edge[->] node[font=\tiny\ttfamily,above] {pdflatex} (pdf);
\end{tikzpicture}
\end{document}

With quotes syntax:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,quotes}
\begin{document}
\begin{tikzpicture}
  \node (tex) [fill=orange, text=white] {TEX};
  \node (pdf) [fill={rgb:red,244;green,15;blue,2},
    text=white, right=of tex] {PDF};
  \draw (tex)
    edge["pdflatex" {font=\ttfamily\tiny,above},->] (pdf);
\end{tikzpicture}
\end{document}

With style definitions:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,quotes}
\begin{document}
\begin{tikzpicture}[
    every node/.style={font=\large,text=white},
    every edge/.style={draw,->},
    every edge quotes/.style={auto,font=\ttfamily\tiny,text=black,fill=none}
  ]
  \node (tex) [fill=orange] {TEX};
  \node (pdf) [fill={rgb:red,244;green,15;blue,2},right=of tex] {PDF};
  \draw (tex) edge["pdflatex"] (pdf);
\end{tikzpicture}
\end{document}

More nodes:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,quotes}
\begin{document}
\begin{tikzpicture}[
    every node/.style = {text=white, minimum width = 1.1cm},
    every edge/.style = {draw,->},
    every edge quotes/.style = {auto, font=\tiny\ttfamily, text=black}]
  ]
  \node (tex) [fill=orange] {TEX};
  \node (pdf) [fill={rgb:red,244;green,15;blue,2}, right = of tex] {PDF};
  \node (dvi) [fill=blue, above = of tex] {DVI};
  \node (ps)  [fill=black!60,above = of pdf] {PS};
\end{tikzpicture}
\end{document}

More nodes with edges:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,quotes}
\begin{document}
\begin{tikzpicture}[
    every node/.style = {text=white, minimum width = 1.1cm},
    every edge/.style = {draw,->},
    every edge quotes/.style = {auto, font=\tiny\ttfamily, text=black}]
  ]
  \node (tex) [fill=orange] {TEX};
  \node (pdf) [fill={rgb:red,244;green,15;blue,2},right = of tex] {PDF};
  \node (dvi) [fill=blue, above = of tex] {DVI};
  \node (ps)  [fill=black!60, above = of pdf] {PS};
  \draw (tex) edge["pdflatex"] (pdf);
  \draw (tex) edge["latex"]    (dvi);
  \draw (dvi) edge["dvips"]    (ps);
  \draw (dvi) edge["dvipdfmx"] (pdf);
  \draw (ps)  edge["ps2pdf"]   (pdf);
\end{tikzpicture}
\end{document}

Sloped edge texts:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,quotes}
\begin{document}
\begin{tikzpicture}[
    every node/.style = {font=\large, text=white},
    every edge/.style = {draw, ->},
    every edge quotes/.style = {auto, font=\ttfamily\tiny,
      text=black, fill=none, sloped}]
  \node (tex) [fill = orange] {TEX};
  \node (pdf) [fill = {rgb:red,244;green,15;blue,2}, right = of tex] {PDF};
  \node (dvi) [fill = blue, above = of tex] {DVI};
  \node (ps)  [fill = black!60, above = of pdf] {PS};
  \draw (tex) edge["pdflatex"] (pdf);
  \draw (tex) edge["latex"]    (dvi);
  \draw (dvi) edge["dvips"]     (ps);
  \draw (ps)  edge["ps2pdf"]   (pdf);
  \draw (dvi) edge["dvipdfmx"] (pdf);
\end{tikzpicture}
\end{document}

The to operation

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
  \node (tex) [fill=orange, text=white] {TEX};
  \node (pdf) [fill={rgb:red,244;green,15;blue,2},
    text=white, right=of tex] {PDF};
  \draw[->] (tex) to[out=45, in=225, looseness=1.5] (pdf);
\end{tikzpicture}
\end{document}

Comparing –, to, and edge

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
  \node (1) {1};
  \node (2) [right = of 1] {2};
  \node (3) [right = of 2] {3};
  \draw[->] (1) -- (2)
            (2) -- (3);
  \node (4) [below = of 1] {1};
  \node (5) [right = of 4] {2};
  \node (6) [right = of 5] {3};
  \draw [->] (4) to (5)
             (5) to (6);
  \node (7) [below = of 4] {1};
  \node (8) [right = of 7] {2};
  \node (9) [right = of 8] {3};
  \draw[->, color=red, very thick] (7) edge (8)
            (8) edge (9);
\end{tikzpicture}
\end{document}