In PSTricks there exist the fillstyles vlines, hlines, crosshatch which have counterparts in tikz patterns library.

However, in PSTricks they can be modified by following options: hatchwidth, hatchwidthinc, hatchsep, hatchsepinc, hatchcolor and hatchangle.

The answer to the question Custom and built in TikZ fill patterns declares a pgfpattern with variables: hatchthickness, hatchspread and hatchcolor.

I am missing hatchangle.

If someone is more familiar with pgf basic layer to adjust this, I am happy to see this as an answer.

BTW, I am aware of Rotate the fill pattern with the shape in tikz [duplicate]. But I think declaring a custom pattern with a variable hatchangle should be possible.

(pgf/tikz version 3.0, Dec 2013)

Relevant code which has to be modified

% defining the new dimensions and parameters
\newcommand{\hatchangle}{} % NEW
% declaring the keys in tikz
         hatchshift/.code={\setlength{\hatchshift}{#1}},% must be >= 0
% setting the default values
         hatchshift=0pt,% must be >= 0
% declaring the pattern
\pgfdeclarepatternformonly[\hatchangle,\hatchspread,\hatchthickness,\hatchshift,\hatchcolor]% variables
   {vlines}% name
   {\pgfqpoint{\dimexpr-2\hatchthickness}{\dimexpr-2\hatchthickness}}% lower left corner
   {\pgfqpoint{\dimexpr\hatchspread+2\hatchthickness}{\dimexpr\hatchspread+2\hatchthickness}}% upper right corner
   {\pgfqpoint{\dimexpr\hatchspread}{\dimexpr\hatchspread}}% tile size
   {% shape description
    \ifdim \hatchshift > 0pt
%    \pgfsetdash{{1pt}{1pt}}{0pt}% dashing cannot work correctly in all situation this way
  • 1
    Hatches are not continuous lines but small patches tiled up. If you have different angled lines you need to make sure that lines ... line up continously. That's why it is not that simple to achieve that. If you use angles then hatch density must be commensurable with the number of hatch lines to guarantee continuity. – percusse Jul 24 '14 at 10:25
  • Do you know how pstricks achieves this? – Hotschke Jul 24 '14 at 10:27
  • 1
    Have a look at TikZ patterns with dimensions parameters by Alberto Sartori. It shows how to modify patterns. – Andrew Jul 24 '14 at 12:38
  • 1
    Hotschke: No, not really. @Andrew He is luckily one of the residents and here is a related one tex.stackexchange.com/questions/119710/…. – percusse Jul 24 '14 at 13:37

Mathematically this is how you implement line-patterns with various angles.

CAUTION: Do not try this with angle closed to 0, 90, 180, etc!!


    {\pgfqpoint{\dimexpr\patternwidth pt+2\hatchthickness}{\dimexpr\patternheight pt+2\hatchthickness}}
    {\pgfpoint{\patternwidth}{\patternheight}} % \patternwidth and patternheight is calculated as follows
        \ifdim\hatchangle pt<90pt
            \pgfpathlineto{\pgfqpoint{\patternwidth pt}{\patternheight pt}}
            \pgfpathmoveto{\pgfqpoint{\patternwidth pt}{0pt}}
            \pgfpathlineto{\pgfqpoint{0pt}{\patternheight pt}}

\foreach\i in{5,15,...,360}{


By the way, I ignore the shift option. It is not the core part of the implementation.

| improve this answer | |

Tikz library patterns.meta by Mark Wibrow

provides the patterns Lines[angle=22.50] and Hatch[angle=22.5]

\usetikzlibrary{patterns, patterns.meta}
    \draw[pattern={horizontal lines},pattern color=orange]
    (0,0) rectangle +(1,1);
    \draw[pattern={Lines[yshift=-10pt]},pattern color=blue]
    (0,0) rectangle +(1,1);
    \draw[pattern={vertical lines},pattern color=orange]
    (1,0) rectangle +(1,1);
    \draw[pattern={Lines[angle=90,yshift=-2pt]},pattern color=blue]
    (1,0) rectangle +(1,1);
    \draw[pattern={north east lines},pattern color=orange]
    (0,1) rectangle +(1,1);
    \draw[pattern={Lines[angle=45,distance={3pt/sqrt(2)}]},pattern color=blue]
    (0,1) rectangle +(1,1);
    \draw[pattern={north west lines},pattern color=orange]
    (1,1) rectangle +(1,1);
    \draw[pattern={Lines[angle=-22.5,distance={8pt/sqrt(2)}]},pattern color=blue]
    (1,1) rectangle +(1,1);

enter image description here

This library is marked in pgf/tikz version 3.1 as experimental.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.