# TikZ: offsetting a fill pattern

TikZ provides fill patterns (section 15.5.1 in the docs).

Instead of filling a path with a single solid color, it is also possible to fill it with a tiling pattern. Imagine a small tile that contains a simple picture like a star. Then these tiles are (conceptually) repeated infinitely in all directions, but clipped against the path.

Is there an option to offset the pattern? So that the tiles at the edge of the pattern are (conceptually) cut off at a specific place?

I tried combining pattern with clip, but it didn't change anything.

\clip (0, 0) rectangle (1, 1);
\fill [pattern color=black, pattern=fivepointed stars] (-0.8, -0.7) rectangle (1, 1);


Both

\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\fill[pattern color=black, pattern=fivepointed stars] (0, 0) rectangle (1, 1);
\end{tikzpicture}
\end{document}


and

\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\clip (0, 0) rectangle (1, 1);
\fill[pattern color=black, pattern=fivepointed stars] (-0.2, -0.3) rectangle (1, 1);
\end{tikzpicture}
\end{document}


produce

I am looking for a way to get something like this

where the pattern is just offset compared to the first drawing.

• I'm not sure I fully understand what you want exactly. Could you provide a small complete document with a tikzpicture in it to illustrate the situation, in two versions side by side, one without clip and one with clip, and add a screenshot to the question? Oct 15, 2020 at 15:23

With patterns.meta library is possible to define shifting for certain patterns.

\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns,patterns.meta}
\begin{document}
\begin{tikzpicture}
\draw[pattern=Stars, pattern color=red] (0,0) rectangle +(1, 1);

\draw[pattern={Stars[xshift=2pt,yshift=3pt]}, pattern color=blue] (0,0) rectangle +(1, 1);
\end{tikzpicture}
\end{document}


In pgfmanual.pdf, which is the documentation for Tikz and PGF, v. 3.1.4b, p. 1152, we read:

Second, the phase of patterns is not well-defined, that is, it is not clear where the origin of the “first” tile is. To be more precise, PostScript and pdf on the one hand and svg on the other hand define the origin differently. PostScript and pdf define a fixed origin that is independent of where the path lies. This has the highly desirable effect that if you use the same pattern to fill multiple paths, the outcome is the same as if you had filled a single path consisting of the union of all these paths. By comparison, svg uses the upper-left (?) corner of the path to be filled as the origin. However, the svg specification is a bit vague on this question.