The TikZ and PGF Packages
Manual for version 3.1.10
Libraries
62 Pattern Library¶
-
TikZ Library patterns ¶
\usepgflibrary{patterns} %
LaTeX
and plain
TeX
and pure pgf
\usepgflibrary[patterns] % ConTeXt and pure pgf
\usetikzlibrary{patterns} %
LaTeX
and plain
TeX
when using TikZ
\usetikzlibrary[patterns] % ConTeXt when using TikZ
The package defines patterns for filling areas.
62.1 Form-Only Patterns¶
Pattern name | Example (pattern in black, blue, and red on faded checkerboard) |
horizontal lines | |
vertical lines | |
north east lines | |
north west lines | |
grid | |
crosshatch | |
dots | |
crosshatch dots | |
fivepointed stars | |
sixpointed stars | |
bricks | |
checkerboard |
62.2 Inherently Colored Patterns¶
Pattern name | Example |
checkerboard light gray | |
horizontal lines light gray | |
horizontal lines gray | |
horizontal lines dark gray | |
horizontal lines light blue | |
horizontal lines dark blue | |
crosshatch dots gray | |
crosshatch dots light steel blue |
62.3 User-Defined Patterns¶
by Mark Wibrow
-
TikZ Library patterns.meta ¶
\usepgflibrary{patterns.meta} %
LaTeX
and plain
TeX
and pure pgf
\usepgflibrary[patterns.meta] % ConTeXt and pure pgf
\usetikzlibrary{patterns.meta} %
LaTeX
and plain
TeX
when using TikZ
\usetikzlibrary[patterns.meta] % ConTeXt when using TikZ
Define your own patterns with a syntax similar to arrows.meta.
Caveat: This library is currently experimental and might change without notice. There are some known shortcomings that will hopefully be fixed in the future.
-
\pgfdeclarepattern{⟨config⟩} ¶
-
/pgf/patterns/name=⟨name⟩(no default) ¶
-
/pgf/patterns/type=⟨type⟩ (default uncolored) ¶
-
• uncolored the pattern will obey the surrounding color.
-
• colored the pattern will have an intrinsic color.
-
• form only synonym for uncolored
-
• inherently colored synonym for colored
-
/pgf/patterns/x=⟨dimension⟩ (default 1cm) ¶
-
/pgf/patterns/y=⟨dimension⟩ (default 1cm) ¶
-
/pgf/patterns/parameters=⟨comma separated list⟩ (default empty) ¶
-
/pgf/patterns/defaults=⟨comma separated list⟩ (default empty) ¶
-
/pgf/patterns/bottom left=⟨pgfpoint⟩(no default) ¶
-
/pgf/patterns/top right=⟨pgfpoint⟩(no default) ¶
-
/pgf/patterns/tile size=⟨pgfpoint⟩(no default) ¶
-
/pgf/patterns/tile transformation=⟨pgftransformation⟩ (default empty) ¶
-
/pgf/patterns/code=⟨code⟩(no default) ¶
-
/pgf/patterns/set up code=⟨code⟩ (default empty) ¶
This command is used to declare a new pattern. In contrast to the normal patterns and in the spirit of arrows.meta this command takes a list of keys and values to define the pattern. The following keys are available:
The name of the pattern by which it can be used later on.
The type of the pattern maps to what was called “form only” and “inherently colored” in the language of the normal patterns. The available choices are:
Unit vector of the coordinate system in the \(x\)-direction.
Unit vector of the coordinate system in the \(y\)-direction.
A list of parameters that are passed to the pattern. This is usually a list of TeX macros. It is very important that these macros are fully expandable because the values they hold are being used for deduplication in the PDF file.
This list holds default assignments to the parameters passed to the pattern. The default keys can then be found under the /pgf/pattern keys/ prefix.
Bottom left corner of the pattern’s bounding box, e.g. \pgfqpoint{-.1pt}{-.1pt}.
Top right corner of the pattern’s bounding box, e.g. \pgfqpoint{3.1pt}{3.1pt}.
Width and height of a single of the pattern as a pgf point specification, i.e. the \(x\) coordinate is the width and the \(y\) coordinate is the height, e.g. \pgfqpoint{3pt}{3pt}.
A pgf transformation, e.g. \pgftransformrotate{30}.
The code should be pgf code that can be protocolled. It should not contain any color code or nodes.
This code can be set if parameters have to be preprocessed before the actual pattern code can be run.
There are a couple of predefined pgf patterns which are similar to their normal counterparts. For all of these the xshift and yshift are applied before the rotation. If you want to rotate before shifting, just rotate in the drawing code.
-
Pattern Lines
-
/pgf/pattern keys/distance(initially 3pt) ¶
-
/pgf/pattern keys/angle(initially 0) ¶
-
/pgf/pattern keys/xshift(initially 0pt) ¶
-
/pgf/pattern keys/yshift(initially 0pt) ¶
-
/pgf/pattern keys/line width(initially \the\pgflinewidth) ¶
The Lines pattern replaces four patterns: horizontal lines, vertical lines, north east lines, and north west lines. Unfortunately, due to the way the old patterns are constructed, namely that they are not simply related to each other by rotation, the Lines pattern cannot be used as a drop-in replacement.
However, the pattern options can be tuned to resemble the other versions closely. The available parameters are:
Distance between lines.
By default the lines are horizontal. The whole pattern is rotated by this angle. The rotation angle is measured in the mathematically positive sense.
Shifts the whole pattern in \(x\)-direction (before applying the rotation).
Shifts the whole pattern in \(y\)-direction (before applying the rotation).
Thickness of the lines.
The following settings can be used to reproduce the other ... lines patterns.
-
Pattern Hatch
-
/pgf/pattern keys/distance(initially 3pt)
-
/pgf/pattern keys/angle(initially 0)
-
/pgf/pattern keys/xshift(initially 0pt)
-
/pgf/pattern keys/yshift(initially 0pt)
-
/pgf/pattern keys/line width(initially \the\pgflinewidth)
The Hatch pattern replaces the grid and crosshatch patterns. The Hatch pattern without options is a drop-in replacement for the grid pattern.
Distance between crosses.
By default the lines are horizontal and vertical. The whole pattern is rotated by this angle. The rotation angle is measured in the mathematically positive sense.
Shifts the whole pattern in \(x\)-direction (before applying the rotation).
Shifts the whole pattern in \(y\)-direction (before applying the rotation).
Thickness of the lines.
The following settings can be used to reproduce the grid and crosshatch patterns.
-
Pattern Dots
-
/pgf/pattern keys/distance(initially 3pt)
-
/pgf/pattern keys/angle(initially 0)
-
/pgf/pattern keys/xshift(initially 0pt)
-
/pgf/pattern keys/yshift(initially 0pt)
-
/pgf/pattern keys/radius(initially 0.5pt) ¶
The Dots pattern replaces the dots and crosshatch dots patterns. The Dots pattern without options is a drop-in replacement for the dots pattern.
Distance between dots.
By default the lines are arranged on a regular grid. The whole pattern is rotated by this angle. The rotation angle is measured in the mathematically positive sense.
Shifts the whole pattern in \(x\)-direction (before applying the rotation).
Shifts the whole pattern in \(y\)-direction (before applying the rotation).
Radius of the dots.
The following settings can be used to reproduce the dots and crosshatch dots patterns.
-
Pattern Stars
-
/pgf/pattern keys/distance(initially 3mm)
-
/pgf/pattern keys/angle(initially 0)
-
/pgf/pattern keys/xshift(initially 0pt)
-
/pgf/pattern keys/yshift(initially 0pt)
-
/pgf/pattern keys/radius(initially 1mm)
-
/pgf/pattern keys/points(initially 5) ¶
The Stars pattern replaces the fivepointed stars and sixpointed stars patterns. However, the stars of the Stars pattern are constructed in a fundamentally different fashion, so it can’t be used as a drop-in replacement.
Distance between stars.
By default the stars are arranged on a regular grid. The whole pattern is rotated by this angle. The rotation angle is measured in the mathematically positive sense.
Shifts the whole pattern in \(x\)-direction (before applying the rotation).
Shifts the whole pattern in \(y\)-direction (before applying the rotation).
Outer radius of the enclosing circle of the stars.
Number of pointy ends of the stars.
-
\tikzdeclarepattern{⟨config⟩} ¶
-
/tikz/patterns/bottom left=⟨point⟩(no default) ¶
-
/tikz/patterns/top right=⟨point⟩(no default) ¶
-
/tikz/patterns/tile size=⟨point⟩(no default) ¶
-
/tikz/patterns/tile transformation=⟨transformation⟩(no default) ¶
-
/tikz/patterns/bounding box=⟨point⟩ and ⟨point⟩(no default) ¶
-
/tikz/patterns/infer tile bounding box=⟨dimension⟩ (default 0pt) ¶
A pattern declared with \pgfdeclarepattern can only execute pgf code. This command extends the functionality to also allow TikZ code. All the same keys of \pgfdeclarepattern are valid, but some of them have been overloaded to give a more natural TikZ syntax.
Instead of a pgf name point, this key takes a TikZ point, e.g. (-.1,-.1).
Instead of a pgf name point, this key takes a TikZ point, e.g. (3.1,3.1).
Instead of a pgf name point, this key takes a TikZ point, e.g. (3,3).
Instead of a pgf transformation, this key takes a list of keys and value and extracts the resulting transformation from them, e.g. rotate=30.
In addition to the overloaded keys, some new keys have been added.
This is a shorthand to set the bounding box. It will assign the first point to bottom left and the second point to top right.
Instead of specifying the bounding box by hand, you can ask TikZ to infer the size of the bounding box for you. The ⟨dimension⟩ parameter is padding that is added around the bounding box.
Instead of macros you can also use pgf keys as parameters, if that is what you prefer.