Chapter 8 – Decorating Paths

[xyz-ips snippet=”intro”]

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

[xyz-ips snippet=”fig1″]Figure 8.1 – A simple triangle path[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[orange, line width=3mm]
  (90:2) -- (210:2) -- (330:2) -- cycle;
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.2 – A repeated path with multiple colors and different widths[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw[red, line width=5mm]
    (90:2) -- (210:2) -- (330:2) -- cycle;
  \draw[orange, line width=3mm]
    (90:2) -- (210:2) -- (330:2) -- cycle;
  \draw[yellow, line width=1mm]
    (90:2) -- (210:2) -- (330:2) -- cycle;
\end{tikzpicture}
\end{document}

Preactions and postactions:

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw[orange, line width=3mm,
    preaction =  {draw, red,    line width=5mm},
    postaction = {draw, yellow, line width=1mm}]
    (90:2) -- (210:2) -- (330:2) -- cycle;
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.3 – An arrow with and without decoration[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw[-stealth] (0,0) --(2,0);
\end{tikzpicture}
\end{document}
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
  \draw[-stealth,postaction=decorate,
    decoration={markings,
    mark = between positions 0.2 and 1 step 0.2
    with {\arrow{stealth}}}]
      (0,0) --(2,0);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.4 – Arrowhead markings along a curvy path[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\draw[-stealth, postaction=decorate,
  decoration = {markings, mark = between positions 0.1
  and 1 step 0.1 with {\arrow{stealth}}}]
      (0,0) arc(180:0:1) arc(-180:0:1);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.5 – A zigzag arrow[xyz-ips snippet=”fig2″]

Decorated edge:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathmorphing}
\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[->, decorate, decoration=zigzag] (pdf);
\end{tikzpicture}
\end{document}

Decorated path:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathmorphing}
\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[decorate, decoration=zigzag, ->] (tex) -- (pdf);
\end{tikzpicture}
\end{document}

Some syntax examples for testing follow.

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
  \draw (0,0) decorate[decoration=bumps] {arc(180:0:1)} --cycle;
\end{tikzpicture}
\end{document}
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
  \draw[->] decorate[decoration=zigzag] {(0,0) -- (1.5,0)};
\end{tikzpicture}
\end{document}

Options to \draw:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
  \draw[->,decorate,decoration=zigzag] (0,0) -- (1.5,0);
\end{tikzpicture}
\end{document}

Option to tikzpicture:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}[decoration=zigzag]
  \draw[->,decorate] (0,0) -- (1.5,0);
\end{tikzpicture}
\end{document}

Start drawing:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
  \draw (0,0) -- (1,0) arc(180:0:1) -- (4,0);
\end{tikzpicture}
\end{document}

Decorating only the arc:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
  \draw (0,0) -- (1,0)
    decorate[decoration=zigzag] {arc(180:0:1)} -- (4,0);
\end{tikzpicture}
\end{document}

Decorating the full path:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
  \draw[decorate,decoration=zigzag] (0,0) -- (1,0)
    arc(180:0:1) -- (4,0);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.6 – Linear decorations on a line – zigzag, saw, and random steps[xyz-ips snippet=”fig2″]

[xyz-ips snippet=”hint-several”]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
  \draw[decorate,decoration=zigzag] (0,0) -- (2,0);
  \draw[decorate,decoration=saw,yshift=-6mm] (0,0) -- (2,0);
  \draw[decorate,decoration={random steps,segment length=2mm},yshift=-12mm] (0,0) -- (2,0);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.7 – Linear decorations on an arc – zigzag, saw, random steps, and lineto[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
  \draw[decorate,decoration={zigzag,pre=curveto,post=curveto,pre length=4.5mm,post length=3mm}]
    (0,0) arc(180:0:1);
  \draw[decorate,decoration=saw,yshift=-8mm]
    (0,0) arc(180:0:1);
  \draw[decorate,decoration=random steps,yshift=-16mm]
    (0,0) arc(180:0:1);
  \draw[decorate,decoration=lineto,yshift=-20mm]
    (0,0) arc(180:0:1);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.8 – Curvy decorations on a line – bumps, coil, snake, and bent[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
  \draw[decorate,decoration=bumps] (0,0) -- (2,0);
  \draw[decorate,decoration={coil, amplitude=2mm,segment length=2mm},yshift=-4.5mm] (0,0) -- (2,0);
  \draw[decorate,decoration={snake},yshift=-10mm] (0,0) -- (2,0);
  \draw[decorate,decoration={bent},yshift=-14mm] (0,0) -- (2,0);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.9 – Curvy decorations on an arc – bumps, coil, snake, and lineto[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
  \draw[decorate,decoration={bumps,pre=curveto,post=curveto,pre length=4.5mm,post length=3mm},yshift=-7mm]
    (0,0) arc(180:0:1);
  \draw[decorate,decoration={coil, amplitude=2mm,segment length=2mm},yshift=-16mm]
    (0,0) arc(180:0:1);
  \draw[decorate,decoration={snake,pre=curveto,post=curveto,pre length=1.1mm,post length=0},yshift=-24mm]
    (0,0) arc(180:0:1);
  \draw[decorate,decoration=lineto,yshift=-28mm]
    (0,0) arc(180:0:1);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.10 – Path replacing decorations: border, waves, expanding waves, ticks, brace[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
  \draw[decorate,decoration={border,segment length=1mm}] (0,0) -- (2,0);
  \draw[decorate,decoration={waves,segment length=1mm},yshift=-2.5mm] (0,0) -- (2,0);
  \draw[decorate,decoration={expanding waves,angle=10,segment length=1mm},yshift=-7.6mm] (0,0) -- (2,0);
  \draw[decorate,decoration={ticks,segment length=1mm},yshift=-13mm] (0,0) -- (2,0);
  \draw[decorate,decoration={brace,segment length=1mm},yshift=-16mm] (0,0) -- (2,0);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.11 – A ticks decoration as a post-action[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
  \draw[postaction = {draw, decorate,
    decoration = {ticks, segment length=1mm}}]
    (0,0) -- (2,0);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.12 – Brace decorations for rectangle sides[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[decoration=brace, font=\sffamily\tiny]
  \draw (0,0) rectangle (2,1);
  \draw[decorate]
    (0,1.05) -- node[above] {2 cm} (2,1.05);
  \draw[decorate]
    (2.05,1) -- node[above, sloped] {1 cm} (2.05,0);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.13 – Text along a curvy path[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
  \draw[decorate,
    decoration={text along path,
    text=text follows the path}]
    (0,0) arc(180:0:1);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.14 – Text along a path with multiple segments[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
  \draw[decorate, decoration = {text along path,
    text = {This is a long text along a path}}]
    (0,0) -- (1,0) arc(150:30:1.4) -- (5,0);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.15 – Arrows along a path – stealth, triangle, and LaTeX[open][xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings,arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw[
  decorate,
  decoration = {markings, mark = between positions 0
  and 1 step 0.1 with {\arrow{stealth}}}]
      (0,0) arc(120:60:1) arc(-120:-60:1);
\draw[yshift=-3mm,
  decorate,
  decoration = {markings, mark = between positions 0
  and 1 step 0.1 with {\arrow{Triangle}}}]
      (0,0) arc(120:60:1) arc(-120:-60:1);
\draw[yshift=-6mm,
  decorate,
  decoration = {markings, mark = between positions 0
  and 1 step 0.1 with {\arrow{LaTeX[open]}}}]
      (0,0) arc(120:60:1) arc(-120:-60:1);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.16 – Shapes along a path – star, diamond, starburst, and signal[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.shapes,shapes}
\begin{document}
\begin{tikzpicture}
\draw[decorate,
  decoration = {shape backgrounds, shape=star, shape size=2mm}]
      (0,0) arc(120:60:1) arc(-120:-60:1);
\draw[decorate, yshift=-3mm,
  decoration = {shape backgrounds, shape=diamond, shape size=2mm}]
      (0,0) arc(120:60:1) arc(-120:-60:1);
\draw[decorate, yshift=-6mm,
  decoration = {shape backgrounds, shape=starburst, shape size=2mm}]
      (0,0) arc(120:60:1) arc(-120:-60:1);
\draw[decorate, yshift=-9mm,
  decoration = {shape backgrounds, shape=signal, shape size=2mm}]
      (0,0) arc(120:60:1) arc(-120:-60:1);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.17 – Smileys along a path[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset{smiley/.pic={
  \draw[shading=ball, ball color=yellow] (0,0)
    circle [radius=2];
  \draw[shading=ball, ball color=black] (-0.5,0.5,0)
    ellipse [x radius=0.2, y radius=0.4];
  \draw[shading=ball, ball color=black] (0.5,0.5,0)
    ellipse [x radius=0.2, y radius=0.4];
  \draw[very thick] (-1,-1) arc [start angle=185,
    end angle=355, x radius=1, y radius=0.5];}}
\begin{document}
\begin{tikzpicture}
\draw[decorate,
  decoration = {markings, mark = between positions 0
  and 1 step 0.04 with {\pic {smiley};}}]
      (0,0) arc(120:60:40) arc(-120:-60:40);
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.18 – Multiple decorations on a path[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,0)
  decorate[decoration=bumps]  { -- (1,0) }
  decorate[decoration=zigzag] { -- (2,0) }
  decorate[decoration=saw]    { -- (3,0) };
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.19 – The Koch snowflake decoration[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.fractals}
\begin{document}
\begin{tikzpicture}[decoration=Koch snowflake]
  \draw decorate{ (0,0) -- (3,0) };
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.20 – The Koch snowflake decoration iterated[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.fractals}
\begin{document}
\begin{tikzpicture}[decoration=Koch snowflake]
  \draw decorate{decorate{ (0,0) -- (3,0) }};
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.21 – The Koch curve after three iterations[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.fractals}
\begin{document}
\begin{tikzpicture}[decoration=Koch snowflake]
  \draw decorate{decorate{decorate{ (0,0) -- (3,0) }}};
\end{tikzpicture}
\end{document}

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

[xyz-ips snippet=”fig1″]Figure 8.22 – The Koch snowflake[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.fractals}
\begin{document}
\begin{tikzpicture}[decoration=Koch snowflake]
  \draw decorate{decorate{decorate{decorate{decorate{
    (210:2) -- (90:2) -- (330:2) -- cycle}}}}};
\end{tikzpicture}
\end{document}

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