我正在尝试将图案条纹背景添加到矩形中,但使用 PDFLatex 生成的 PDF 会产生几个完全黑色的矩形,而不是用图案填充的矩形。以下代码取自问题的答案使用带有变量的仅限形式模式:可能是 TikZ 错误。
TikZ代码:
\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}
结果如下图所示:
我究竟做错了什么?