I would like to have a rectangle that has some hatch. Furthermore, the hatch should have some shading. But, I am only able to get a transition of the colors in the background. Does anyone know how to only have a color gradient in the hatch with only a white background?

Thanks a lot.

\fill[left color=blue!40, right color=white, postaction={pattern=north west lines, pattern color=blue!40}] (0,0) rectangle (3,3);
  • 1
    Maybe help: tex.stackexchange.com/a/393131/31034
    – user31034
    Jun 9, 2019 at 16:23
  • Thank you. I have found this as well. But was not able to adapt it to a north west pattern and defining the dimensions in the tikz environment...
    – Sir Sy
    Jun 9, 2019 at 16:53

2 Answers 2


Only for fun!


\draw[blue, thick] (0,0) rectangle (\a,\a);
\foreach \x [count=\i] in{0,0.1,0.2,...,\a}{
\draw [blue,line width=\lw mm,opacity=\i/45](\x,0)--(0,\x) (\a,\a-\x)--(\a-\x,\a);}


enter image description here


This is conceptually the same as Ignasi's nice answer in that the pattern is in the background color, so it determines what should be left unshaded. And in order to customize the pattern I use this answer. And of course you need to dial a shading angle to make the shading follow the north east lines.

% defining the new dimensions and parameters
% 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[\hatchspread,\hatchthickness,\hatchshift,\hatchcolor]% variables
   {custom north west lines}% 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

\fill[left color=blue!40, right color=white,shading angle=45,line width=2pt,
postaction={pattern=custom north west lines, 
hatchthickness=1pt,hatchcolor=white}] (0,0) rectangle (3,3);

enter image description here

  • I think the lines should extend beyond the bounds of the shape.
    – azetina
    Jun 9, 2019 at 18:01
  • @azetina There are always viewer issues with these patterns. In order to address your comment I (i) changed the code slightly and (ii) took the screen shot from acroread.
    – user121799
    Jun 9, 2019 at 18:15

You must log in to answer this question.

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