PGF/TikZ Manual | PGFplots | TikZ Editor

TikZ and PGF Manual

Libraries

50 Decoration Library

50.1 Overview and Common Options

The decoration libraries define a number of (more or less useful) decorations that can be applied to paths. The usage of decorations is not covered in the present section, please consult Sections 24, which explains how decorations are used in TikZ, and 103, which explains how new decorations can be defined.

The decorations are influenced by a number of parameters that can be set using the decoration option. These parameters are typically shared between different decorations. In the following, the general options are documented (they are defined directly in the decoration module), special-purpose keys are documented with the decoration that uses it.

Since you are encouraged to use these keys to make your own decorations configurable, it is indicated for each key where the value is stored (so that you can access it). Note that some values are stored in dimension registers while others are stored in macros.

  • /pgf/decoration/segment length=dimension (no default, initially 10pt)

  • Many decorations are made up of small segments. This key determines the desired length of such segments.

    This key sets the -dimension \pgfdecorationsegmentlength.

  • /pgf/decoration/aspect=factor (no default, initially 0.5)

  • For some decorations there is a natural aspect ratio. For instance, for a brace decoration the aspect ratio determines where the brace point will be.

    This key sets the -macro \pgfdecorationsegmentaspect.

  • /pgf/decoration/end radius=dimension (no default, initially 2.5pt)

  • For some decorations there is a natural end radius (of some circle, presumably).

    This key stores the value directly inside the key.

50.2 Handling “Dimension too large” errors

In case you should run into a “Dimension too large error” when using the decorations libraries, there is a pretty high chance that you can resolve this by using the fpu library in combination with /pgf/fpu/install only={reciprocal}. Please note that this key should only be applied locally to avoid other errors (see also at the definition of this key in section 56.2).

(-tikz- diagram)

\usetikzlibrary {decorations.markings,fpu}
\begin{tikzpicture}
\begin{scope}[/pgf/fpu/install only={reciprocal}]
\draw[postaction=decorate,decoration={
markings,mark=at position 0.52 with {
\draw circle[radius=2pt];
}}
,
] plot[smooth,variable=\x,domain=-1:1] (\x*\x*\x,\x*\x);
\end{scope}
\end{tikzpicture}
50.3 Path Morphing Decorations
50.3.1 Decorations Producing Straight Line Paths

The following deformations use only straight lines in order to morph the paths.

  • Decoration lineto

  • This decoration replaces the path by straight lines. For each curve, the path simply goes directly from the start point to the end point. In the following example, the arc actually consist of two subcurves.

    This decoration is actually always defined when the decoration module is loaded, but it is documented here for consistency.

    (-tikz- diagram)

    \usetikzlibrary {decorations}
    \begin{tikzpicture}[decoration=lineto]
    \draw [help lines] grid (3,2);
    \draw [decorate,fill=yellow!80!black]
    (0,0) -- (3,1) arc (0:180:1.5 and 1) -- cycle;
    \end{tikzpicture}
  • Decoration straight zigzag

  • This (meta-)decoration decorates the path by alternating between curveto and zigzag decorations. It always finishes with the curveto decoration. The following parameters influence the decoration:

    • amplitude determines how much the zigzag line raises above and falls below a straight line to the target point.

    • segment length determines the length of a complete “up-down” cycle.

    • meta-segment length determines the length of the curveto and the zigzag decorations.

    (-tikz- diagram)

    \usetikzlibrary {decorations.pathmorphing}
    \begin{tikzpicture}[decoration={straight zigzag,meta-segment length=1.1cm}]
    \draw [help lines] grid (3,2);
    \draw [decorate,fill=yellow!80!black]
    (0,0) -- (3,1) arc (0:180:1.5 and 1) -- cycle;
    \end{tikzpicture}
  • Decoration random steps

  • This decoration consists of straight line segments. The line segments head towards the target, but each step is randomly shifted a little bit. The following parameters influence the decorations:

    • segment length determines the basic length of each step.

    • amplitude The end of each step is perturbed both in \(x\)- and in \(y\)-direction by two values drawn uniformly from the interval \([-d,d]\), where \(d\) is the value of amplitude.

    (-tikz- diagram)

    \usetikzlibrary {decorations.pathmorphing}
    \begin{tikzpicture}
    [decoration={random steps,segment length=2mm}]
    \draw [help lines] grid (3,2);
    \draw [decorate,fill=yellow!80!black]
    (0,0) -- (3,1) arc (0:180:1.5 and 1) -- cycle;
    \end{tikzpicture}
  • Decoration saw

  • This decoration looks like the blade of a saw. The following parameters influence the decoration:

    • amplitude determines how much each spike raises above the straight line.

    • segment length determines the length each spike.

    (-tikz- diagram)

    \usetikzlibrary {decorations.pathmorphing}
    \begin{tikzpicture}[decoration=saw]
    \draw [help lines] grid (3,2);
    \draw [decorate,fill=yellow!80!black]
    (0,0) -- (3,1) arc (0:180:1.5 and 1) -- cycle;
    \end{tikzpicture}
  • Decoration zigzag

  • This decoration looks like a zigzag line. The following parameters influence the decoration:

    • amplitude determines how much the zigzag line raises above and falls below a straight line to the target point.

    • segment length determines the length of a complete “up-down” cycle.

    (-tikz- diagram)

    \usetikzlibrary {decorations.pathmorphing}
    \begin{tikzpicture}[decoration=zigzag]
    \draw [help lines] grid (3,2);
    \draw [decorate,fill=yellow!80!black]
    (0,0) -- (3,1) arc (0:180:1.5 and 1) -- cycle;
    \end{tikzpicture}
50.3.2 Decorations Producing Curved Line Paths
  • Decoration bumps

  • This decoration replaces the path by little half ellipses. The following parameters influence it.

    • amplitude determines the height of the half ellipse.

    • segment length determines the width of the half ellipse.

    (-tikz- diagram)

    \usetikzlibrary {decorations.pathmorphing}
    \begin{tikzpicture}[decoration=bumps]
    \draw [help lines] grid (3,2);
    \draw [decorate,fill=yellow!80!black]
    (0,0) -- (3,1) arc (0:180:1.5 and 1) -- cycle;
    \end{tikzpicture}
  • Decoration coil

  • This decoration replaces the path by a coiled line. To understand how this works, imagine a three-dimensional spring. The spring’s axis points along the path toward the target. Then, we “view” the spring from a certain angle. If we look “straight from the side” we will see a perfect sine curve, if we look “more from the front” we will see a coil. The following parameters influence the decoration:

    • amplitude determines how much the coil rises above the path and falls below it. Thus, this is the radius of the coil.

    • segment length determines the distance between two consecutive “curls”. Thus, when the spring is see “from the side” this will be the wave length of the sine curve.

    • aspect determines the “viewing direction”. A value of 0 means “looking from the side” and a value of 0.5, which is the default, means “look more from the front”.

    (-tikz- diagram)

    \usetikzlibrary {decorations.pathmorphing}
    \begin{tikzpicture}[decoration=coil]
    \draw [help lines] grid (3,2);
    \draw [decorate,fill=yellow!80!black]
    (0,0) -- (3,1) arc (0:180:1.5 and 1) -- cycle;
    \end{tikzpicture}

    (-tikz- diagram)

    \usetikzlibrary {decorations.pathmorphing}
    \begin{tikzpicture}
    [decoration={coil,aspect=0.3,segment length=3mm,amplitude=3mm}]
    \draw [help lines] grid (3,2);
    \draw [decorate,fill=yellow!80!black]
    (0,0) -- (3,1) arc (0:180:1.5 and 1) -- cycle;
    \end{tikzpicture}
  • Decoration curveto

  • This decoration simply yields a line following the original path. This means that (ideally) it does not change the path and follows any curves in the path (hence the name). In reality, due to the internals of how decorations are implemented, this decoration actually replaces the path by numerous small straight lines.

    This decoration is mostly useful in conjunction with meta-decorations. It is also actually defined in the decoration module and is always available.

    (-tikz- diagram)

    \usetikzlibrary {decorations.pathmorphing}
    \begin{tikzpicture}[decoration=curveto]
    \draw [help lines] grid (3,2);
    \draw [decorate,fill=yellow!80!black]
    (0,0) -- (3,1) arc (0:180:1.5 and 1) -- cycle;
    \end{tikzpicture}
  • Decoration snake

  • This decoration replaces the path by a line that looks like a snake seen from above. More precisely, the snake is a sine wave with a “softened” start and ending. The following parameters influence the snake:

    • amplitude determines the sine wave’s amplitude.

    • segment length determines the sine wave’s wavelength.

    (-tikz- diagram)

    \usetikzlibrary {decorations.pathmorphing}
    \begin{tikzpicture}[decoration=snake]
    \draw [help lines] grid (3,2);
    \draw [decorate,fill=yellow!80!black]
    (0,0) -- (3,1) arc (0:180:1.5 and 1) -- cycle;
    \end{tikzpicture}
50.4 Path Replacing Decorations
  • Decoration brace

  • This decoration replaces a straight line path by a long brace. The left and right end of the brace will be exactly on the start and endpoint of the decoration. The decoration really only makes sense for paths that are a straight line.

    • amplitude determines how much the brace rises above the path.

    • aspect determines the fraction of the total length where the “middle part” of the brace will be.

    (-tikz- diagram)

    \usetikzlibrary {decorations.pathreplacing}
    \begin{tikzpicture}[decoration=brace]
    \draw [help lines] grid (3,2);
    \draw [decorate] (0,0) -- (3,1);
    \end{tikzpicture}
  • Decoration expanding waves

  • This decoration adds arcs to the path that get bigger along the line towards the target. The following parameters influence the decoration:

    • segment length determines the distance between consecutive arcs.

    • angle determines the opening angle below and above the path. Thus, the total opening angle is twice this angle.

    (-tikz- diagram)

    \usetikzlibrary {decorations.pathreplacing}
    \begin{tikzpicture}[decoration={expanding waves,angle=5}]
    \draw [help lines] grid (3,2);
    \draw [decorate] (0,0) -- (3,1) arc (0:180:1.5 and 1);
    \end{tikzpicture}
  • Decoration moveto

  • This decoration simply jumps to the end of the path using a move-to path operation. It is mainly useful as pre=moveto or post=moveto decorations.

    This decoration is actually always defined when the decoration module is loaded, but it is documented here for consistency.

  • Decoration ticks

  • This decoration replaces the path by straight lines that are orthogonal to the path. The following parameters influence the decoration:

    • segment length determines the distance between consecutive ticks.

    • amplitude determines half the length of the ticks.

    (-tikz- diagram)

    \usetikzlibrary {decorations.pathreplacing}
    \begin{tikzpicture}[decoration=ticks]
    \draw [help lines] grid (3,2);
    \draw [decorate] (0,0) -- (3,1) arc (0:180:1.5 and 1);
    \end{tikzpicture}
  • Decoration waves

  • This decoration replaces the path by arcs that have a constant size. The following parameters influence the decoration:

    • segment length determines the distance between consecutive arcs.

    • angle determines the opening angle below and above the path. Thus, the total opening angle is twice this angle.

    • radius determines the radius of each arc.

    (-tikz- diagram)

    \usetikzlibrary {decorations.pathreplacing}
    \begin{tikzpicture}[decoration={waves,radius=4mm}]
    \draw [help lines] grid (3,2);
    \draw [decorate] (0,0) -- (3,1) arc (0:180:1.5 and 1);
    \end{tikzpicture}
50.5 Marking Decorations
50.5.1 Overview

A marking on a path is any kind of graphic that is placed on a specific position on a path. Markings are useful in rather diverse situations: you can use them to, say, place little “footsteps” along a path as if someone where walking along the path; to place arrow tips on the middle of a path to indicate the “direction” in which something is flowing; or you can use them to place informative information at certain positions of a path.

For historical reasons there are three different libraries for placing marks on a path. They differ in what kind of markings can be added to a path. We start with the most general and most useful of these libraries.

50.6 Arbitrary Markings
50.6.1 Arrow Tip Markings

Frequent markings that are hard to create correctly are arrow tips. For them, two special commands are available when the code of a mark option is executed. (They are only defined in this code):

  • \arrowreversed[options]{arrow end tip}

  • As above, only the arrow end tip is flipped and points in the other direction.

50.6.2 Footprint Markings
50.6.3 Shape Background Markings

The third library for adding markings uses the background paths of certain shapes. This library is included mostly for historical reasons, using the markings library is usually preferable.

  • Decoration crosses

  • This decoration replaces the path by (diagonal) crosses. The following parameters influence the decoration:

    • segment length determines the distance between (the centers of) consecutive crosses.

    • shape height determines the height of each cross.

    • shape width determines the width of each cross.

    (-tikz- diagram)

    \usetikzlibrary {decorations.shapes}
    \begin{tikzpicture}[decoration=crosses]
    \draw [help lines] grid (3,2);
    \draw [decorate] (0,0) -- (3,1) arc (0:180:1.5 and 1);
    \end{tikzpicture}
  • Decoration triangles

  • This decoration replaces the path by triangles that point along the path. The following parameters influence the decoration:

    • segment length determines the distance between consecutive triangles.

    • shape height determines the height of the triangle side that is orthogonal to the path.

    • shape width determines the width of the triangle.

    (-tikz- diagram)

    \usetikzlibrary {decorations.shapes}
    \begin{tikzpicture}[decoration=triangles]
    \draw [help lines] grid (3,2);
    \draw [decorate,fill=yellow!80!black] (0,0) -- (3,1) arc (0:180:1.5 and 1);
    \end{tikzpicture}
50.7 Text Decorations
50.8 Fractal Decorations