# Filling a path with a color and a pattern simultaneously

I would like a rectangle with the following style:

\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\path[fill=gray,pattern=bricks] (0,0) rectangle (5,-1);
\end{tikzpicture}
\end{document}


I use the preceding code but the output is merely:

Why does this method fail? Thank you!

pattern is also a kind of filling. So it overwrites the fill option. But you can use preaction to fill the path with the color before it is filled by the pattern.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\path
[pattern=bricks]
[preaction={fill=gray}]
(0,0) rectangle (5,-1);
\end{tikzpicture}
\end{document}


Another solution would be to save your path in a macro, let's say \mypath and then apply \fill and \pattern to it.

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

\begin{document}
\begin{tikzpicture}
\def\mypath{(0,0) rectangle (5,-1)}
\fill [gray] \mypath;
\pattern [pattern=bricks] \mypath;
\end{tikzpicture}
\end{document}