Chapter 4 – Drawing edges and arrows

[xyz-ips snippet=”intro”]

[xyz-ips snippet=”img1″]04/01[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 4.1 – A basic edge connecting two nodes[xyz-ips snippet=”fig2″]

\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}

[xyz-ips snippet=”img1″]04/02[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 4.2 – An edge with a text label[xyz-ips snippet=”fig2″]

\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:[xyz-ips snippet=”fig2″]

\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:[xyz-ips snippet=”fig2″]

\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}

[xyz-ips snippet=”img1″]04/03[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 4.3 – Four nodes[xyz-ips snippet=”fig2″]

\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}

[xyz-ips snippet=”img1″]04/04[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 4.4 – Many edges with text[xyz-ips snippet=”fig2″]

\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}

[xyz-ips snippet=”img1″]04/05[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 4.5 – Sloped text on edges[xyz-ips snippet=”fig2″]

\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}

[xyz-ips snippet=”img1″]04/06[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 4.6 – Sloped text with the auto=right option[xyz-ips snippet=”fig2″]

\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=right, 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}

[xyz-ips snippet=”img1″]04/07[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 4.7 – Mathematical arrows[xyz-ips snippet=”fig2″]

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[yscale=-1, y=2.5ex]
  \foreach \tip [count=\i] in {
    Classical TikZ Rightarrow, Computer Modern Rightarrow
  } {
    \draw [-{\tip}] (0, \i) to ++(0.5, 0)
      node [right] {\texttt{\tip}};
  }
  \draw [-{Implies}, double, yshift=2.2em] (0,1) to ++(0.5, 0)
    node [right] {\texttt{Implies}};
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]04/08[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 4.8 – Barbed arrows[xyz-ips snippet=”fig2″]

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[yscale=-1, y=2.5ex]
  \foreach \tip [count=\i] in {
    Arc Barb, Bar, Bracket, Hooks, Parenthesis,
    Straight Barb, Tee Barb
  } {
    \draw [-{\tip}] (0, \i) to ++(0.5, 0)
      node [right] {\texttt{\tip}};
  }
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]04/09[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 4.9 – Geometric arrows[xyz-ips snippet=”fig2″]

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[yscale=-1, y=2.5ex]
  \foreach \tip [count=\i] in {
    Circle, Diamond, Ellipse, Kite, Latex, Latex[round],
    Rectangle, Square, Stealth, Stealth[round],
    Triangle, Turned Square
  } {
    \draw [-{\tip}] (0, \i) to ++(0.5, 0)
      node [right] {\texttt{\tip}};
  }
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]04/10[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 4.10 – Open geometric arrows[xyz-ips snippet=”fig2″]

\documentclass[border=1pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[yscale=-1, y=2.5ex]
  \foreach \tip [count=\i] in {
    Circle[open], Diamond[open], Ellipse[open], Kite[open],
    Latex[open], Rectangle[open], Square[open], Stealth[open],
    Triangle[open], Turned Square[open]
  } {
    \draw [-{\tip}] (0, \i) to ++(0.5, 0)
      node [right] {\texttt{\tip}};
  }
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]04/11[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 4.11 – A customized arrow tip[xyz-ips snippet=”fig2″]

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta}
\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[very thick, draw=red,
    -{Stealth[color=orange, fill=red, width=8pt, length=10pt]}]
    (pdf);
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]04/12[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 4.12 – A curvy line with an arrow tip[xyz-ips snippet=”fig2″]

\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

[xyz-ips snippet=”fig2″]

\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}

[xyz-ips snippet=”img1″]04/13[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 4.13 – An undesired arrow tip[xyz-ips snippet=”fig2″]


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:[xyz-ips snippet=”fig2″]

\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.

[xyz-ips snippet=”chapter1″]05[xyz-ips snippet=”chapter2″]