3

I am trying to add a pattern-striped background to a rectangle, but the PDF generated with PDFLatex produces a couple of completely black rectangles instead of the ones filled in with the pattern. The following code is taken form the answer to the question Using form-only patterns with variable: possible TikZ bug.

TikZ code:

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

\tikzset{
    slope/.code={\edef\slope{#1}},
    slope/.default=0.9, slope
}

\makeatletter

\pgfdeclarepatternformonly{stripes}{\pgfpoint{0cm}{0cm}}{\pgfpoint{1cm}{1cm}}{\pgfpoint{1cm}{1cm}} {
    \foreach \i in {0.1, 0.3,...,0.9} {
        \pgfpathmoveto{\pgfpoint{\i cm}{0cm}}
        \pgfpathlineto{\pgfpoint{1cm}{1cm - \i cm}}
        \pgfpathlineto{\pgfpoint{1cm}{1cm - \i cm+ 0.1cm}}
        \pgfpathlineto{\pgfpoint{\i cm - 0.1cm}{0cm}}
        \pgfpathclose%
        \pgfusepath{fill}
        \pgfpathmoveto{\pgfpoint{0cm}{\i cm}}
        \pgfpathlineto{\pgfpoint{1cm - \i cm}{1cm}}
        \pgfpathlineto{\pgfpoint{1cm - \i cm - 0.1cm}{1cm}}
        \pgfpathlineto{\pgfpoint{0cm}{\i cm + 0.1cm}}
        \pgfpathclose%
        \pgfusepath{fill}
    }
}

\pgfdeclarepatternformonly[\tikz@pattern@color,\slope]{slant lines}
    {\pgfpoint{-.1mm/\slope}{-.1mm}}
    {\pgfpoint{1.1mm/\slope}{1.1mm}}
    {\pgfpoint{1mm/\slope}{1mm}}{
        \pgfsetlinewidth{0.4pt}
        \pgfpathmoveto{\pgfpoint{-.1mm/\slope}{-.1mm}}
        \pgfpathlineto{\pgfpoint{1.1mm/\slope}{1.1mm}}
        \pgfsetstrokecolor{\tikz@pattern@color}
        \pgfusepath{stroke}
    }

\makeatother

\begin{document}
\begin{tikzpicture}
    \fill[pattern=stripes, pattern color=red] (0,0) rectangle (5,5);
    \fill[pattern=slant lines, pattern color=blue, slope=0.3] (5,0) rectangle (10,5);
\end{tikzpicture}
\end{document}

The result is shown in the following picture:

enter image description here

What am I doing wrong?

closed as unclear what you're asking by Qrrbrbirlbel, user13907, user31729, R. Schumacher, Paul Gessler Apr 30 '15 at 23:10

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    It is fine on my end with Package: tikz 2013/12/13 v3.0.0 (rcs-revision 1.142). – Jesse Dec 8 '14 at 12:30
  • I will try to update the package, my current version is: tikz.sty 2010/10/13 v2.10 (rcs-revision 1.76), the one that comes packaged with Debian Wheezy (stable). – Ricardo Dec 9 '14 at 12:16

Browse other questions tagged or ask your own question.