[Tex/LaTex] Hatch a rectangle in TikZ

patterntikz-pgf

I know how to make a rectangle and fill it.

But what shoud be done to hatch this rectangle with thin 45 degree inclined line with 2mm gap.

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
%\draw (0,0) rectangle (2,4);
\fill[blue] (0,0) rectangle (2,4);

\end{tikzpicture}

\end{document}

Thank you Altermundus,

I want to hatch area under the curve. But I am unable to use your code as i did with

[pattern=north west lines, pattern color=blue]

Please give little explanation for your code so that i can use it.

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

\begin{document}
\begin{tikzpicture}
\draw[pattern=north west lines, pattern color=blue] (0,0) rectangle (2,4);
\end{tikzpicture}

\begin{tikzpicture}
\draw [thick,pattern=north west lines, pattern color=red] (1,0)--(1,1) to [bend left] (4,4) -- (4,0) --cycle;
\end{tikzpicture}

\end{document}

Best Answer

You can use the library patterns. For example:

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

\begin{document}
\begin{tikzpicture}
\draw[pattern=north west lines, pattern color=blue] (0,0) rectangle (2,4);
\end{tikzpicture}

\end{document}

which gives you as result:

enter image description here

You find much more in the documentation (pgfmanual): Chapter 62 Pattern Library.