4

I want to use the crosshatch dots pattern but in my eyes the density of the dots is too high. This means the distance between the dots is too small for me. I already know that I have to define my own pattern, i.e.

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{patterns}


\pgfdeclarepatternformonly{my crosshatch dots}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{2.5pt}{2.5pt}}{\pgfqpoint{3pt}{3pt}}%
{
    \pgfpathcircle{\pgfqpoint{0pt}{0pt}}{.5pt}
    \pgfpathcircle{\pgfqpoint{1.5pt}{1.5pt}}{.5pt}
    \pgfusepath{fill}
}

\begin{document}
        \begin{tikzpicture}
        \draw[pattern=my crosshatch dots]  (0,0) rectangle (2,2);
        \end{tikzpicture}
\end{document}

The problem is that I don't know which of the parameters have to be changed in which manner - I tried it but the results weren't satisfactory to me. Can someone help me along?

0

1 Answer 1

4

To change a pattern it is necessary to first understand all the macros involved. What happens with

\pgfpathcircle{\pgfqpoint{0pt}{0pt}}{.5pt}
\pgfpathcircle{\pgfqpoint{1.5pt}{1.5pt}}{.5pt}
\pgfusepath{fill}

is that you draw two circles of radius .5pt one at coordinates (0pt,0pt) and the other at (1.5pt,1.5pt) and you repeat them along a path. The pattern is composed of several paths of course. Imagine to have a square, where the bottom left angle is at (-1pt,-1pt) and the top right at (2.5pt,2.5pt). To create the pattern, you fill with dots a path from the left angle to the right angle. Then you move right and repeat the procedure: now this path will be drawn from (-0.7pt, -1pt) to (2.5pt,2.3pt) say and keep repeating. This will fill the lower triangle of the square. The procedure is similar for the top triangle.

As you can imagine, if you want to reduce the number of dots you can: a) increase the distance between the two dots, b) increase the distance between the pair of two dots in the pattern, c) a combination of the two.

In the following, I show an example of method c:

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{patterns}


\pgfdeclarepatternformonly{my crosshatch dots}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{5pt}{5pt}}{\pgfqpoint{6pt}{6pt}}%
{
    \pgfpathcircle{\pgfqpoint{0pt}{0pt}}{.5pt}
    \pgfpathcircle{\pgfqpoint{3pt}{3pt}}{.5pt}
    \pgfusepath{fill}
}

\begin{document}
    \begin{tikzpicture}
    \draw[pattern=my crosshatch dots]  (0,0) rectangle (2,2);
    \end{tikzpicture}
\end{document}

The result:

enter image description here

The best in this case would be to use the optional parameter of \pgfdeclarepatternformonly and define a macro to control the distance. Beware: if you do so, you may want to change all \pgfqpoint into \pgfpoint.

1
  • Thank you for your prompt and detailed answer! Works great!
    – Rorschach
    Commented Aug 8, 2016 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .