有充分的证据表明,TikZ 图案的原点位置不能轻易改变,因为图案本质上是绘制在所有元素后面的不可见画布上,以便它在每个元素内对齐。
我已经为等距网格图案编写了以下内容:
\usetikzlibrary{patterns}
\def\isoScale{0.5}
\pgfmathsetlengthmacro{\patternSize}{\isoScale*2cm}
\pgfmathsetlengthmacro{\patternHalfSize}{\isoScale*1cm}
\pgfmathsetlengthmacro{\patternHeight}{\isoScale*1.1547005384cm}
\pgfdeclarepatternformonly[\patternSize,\patternHalfSize,\patternHeight]{isometric lines}
{\pgfpointorigin}
{\pgfqpoint{\patternSize}{\patternHeight}}
{\pgfqpoint{\patternSize}{\patternHeight}}
{
\pgfsetlinewidth{0.15mm}
\pgfpathmoveto{\pgfqpoint{0cm}{0cm}}
\pgfpathlineto{\pgfqpoint{\patternSize}{\patternHeight}}
\pgfpathmoveto{\pgfqpoint{0cm}{\patternHeight}}
\pgfpathlineto{\pgfqpoint{\patternSize}{0cm}}
\pgfpathmoveto{\pgfqpoint{\patternHalfSize}{0cm}}
\pgfpathlineto{\pgfqpoint{\patternHalfSize}{\patternHeight}}
\pgfpathmoveto{\pgfqpoint{\patternSize}{0cm}}
\pgfpathlineto{\pgfqpoint{\patternSize}{\patternHeight}}
\pgfpathmoveto{\pgfqpoint{0cm}{0cm}}
\pgfpathlineto{\pgfqpoint{0cm}{\patternHeight}}
\pgfusepath{stroke}
}
并试图填充下面的每个矩形:
\begin{tikzpicture}
\fill[pattern=isometric lines] (0,0) rectangle ++(4,4);
\fill[pattern=isometric lines] (0.1,-5) rectangle ++(4,4);
\fill[pattern=isometric lines] (0.2,-5) rectangle ++(4,4);
\end{tikzpicture}
但重要的是,每个填充图案都正确地固定在每个左上角,而不是像现在这样对齐:
我们如何才能实现这一点?当然可以使用除模式之外的其他东西。长话短说,这是一个 MWE,我打算用它来填充 tcolorbox 的背景。