8

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!

2 Answers 2

8

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}

enter image description here

2

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}

enter image description here

You must log in to answer this question.

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