Chapter 4 – Drawing Edges

Here are the Code examples of this chapter. These pages will be updated over time (sectioning, adding pictures, captions, and possibly further examples). I will synchronize the content with GitHub. Finally, the chapter pages and Code examples will be moved to a dedicated website TikZ.org.

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}


Comment:

We use the arrow as edge option, because the edge operation
creates a separate path. It inherits the arrow though. But see what happens here:

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw[->]  (0,0) edge (1,0);
\end{tikzpicture}
\end{document}

We have an undesired arrow at the beginning of the path.

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}