
次の MWE では、定義が異なっているにもかかわらず、すべての図形のパターン カラーが最初のものと同じになっているのはなぜですか?
%%%% pattern-color
\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{chains,patterns,backgrounds}
\makeatletter
\tikzset{
hatch distance/.store in=\hatchdistance,
hatch distance=5pt,
hatch thickness/.store in=\hatchthickness,
hatch thickness=5pt
}
\pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{north east hatch}% name
{\pgfqpoint{-1pt}{-1pt}}% below left
{\pgfqpoint{\hatchdistance}{\hatchdistance}}% above right
{\pgfpoint{\hatchdistance-1pt}{\hatchdistance-1pt}}%
{
\pgfsetcolor{\tikz@pattern@color}
\pgfsetlinewidth{\hatchthickness}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{\hatchdistance}{\hatchdistance}}
\pgfusepath{stroke}
}
\makeatother
\begin{document}
\begin{tikzpicture}[
start chain = going below,
node distance = 2mm,
Node/.style = {minimum width=#1,
shape=rectangle,
draw, fill=white,
on chain},
Pattern/.style = {pattern=north east hatch,
pattern color=#1,%teal!30,
hatch distance=7pt,
hatch thickness=3pt},
font=\small\sffamily]
%----------------
\node[Node=44mm,Pattern=red!30] {desired pattern color: red};
\node[Node=44mm,Pattern=cyan!30,
preaction={fill=yellow}] {desired pattern color: cyan};
\node[Node=44mm] {without pattern};
\node[Node=44mm,Pattern=orange!30,
preaction={fill=gray!30}] {desired pattern color: orange};
%---
\end{tikzpicture}
\end{document}
答え1
これは のバグです\pgfcorepatterns.code.tex
。内部マクロは\pgf@declarepatternmutable
パターン タイプ7
を ではなくとして保存します#7
。修正された行は次のようになります。
\expandafter\gdef\csname pgf@pattern@type@#1\endcsname{#7}%
この変更により、パターンは期待どおりに動作するようになります。
答え2
これは解決策ではありませんが、診断結果です。
フォームのみのパターンのコードはない色コードをまったく含めないでください。したがって、ドキュメントを信じるならば、定義内で色を設定することは絶対に避けるべきです。
しかし、それはすべてを白か黒にしてしまうだけです...
OK。パターンのマニュアルの 1064 ページのコードから始めますstars
。これは宣伝どおりに正常に動作します。
次に、変数を追加します。次のようになります。
\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{patterns}
\tikzset{
hatch distance/.store in=\hatchdistance,
hatch distance=5pt,
hatch thickness/.store in=\hatchthickness,
hatch thickness=5pt
}
\pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{stars}
{\pgfpointorigin}
{\pgfpoint{1cm}{1cm}}
{\pgfpoint{1cm}{1cm}}
{
\pgftransformshift{\pgfpoint{.5cm}{.5cm}}
\pgfpathmoveto{\pgfpointpolar{0}{4mm}}
\pgfpathlineto{\pgfpointpolar{144}{4mm}}
\pgfpathlineto{\pgfpointpolar{288}{4mm}}
\pgfpathlineto{\pgfpointpolar{72}{4mm}}
\pgfpathlineto{\pgfpointpolar{216}{4mm}}
\pgfpathclose%
\pgfusepath{fill}
}
\begin{document}
\begin{tikzpicture}
\filldraw[pattern=stars] (0,0) rectangle (1.5,2);
\filldraw[pattern=stars,pattern color=red](1.5,0) rectangle (3,2);
\end{tikzpicture}
\end{document}
すべてがあまり良くない:
つまり、宣伝どおりには機能しないのです...
マニュアルのこの部分のコードが機能しないという別の質問があります。それを見つけられるかどうか確認してみます (私が質問しました)。同じ問題ではありませんが、手がかりになるかもしれません。
編集
色を変えることが不可能というわけではないのですが…
\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{patterns,chains}
\pgfdeclarepatternformonly{north east hatch}% name
{\pgfqpoint{-1pt}{-1pt}}% below left
{\pgfqpoint{7pt}{3pt}}% above right
{\pgfpoint{6pt}{6pt}}%
{
\pgfsetlinewidth{3pt}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{7pt}{3pt}}
\pgfpathclose
\pgfusepath{stroke}
}
\begin{document}
\begin{tikzpicture}[
start chain = going below,
node distance = 2mm,
Node/.style =
{
minimum width=#1,
shape=rectangle,
draw, fill=white,
on chain
},
Pattern/.style =
{
pattern=north east hatch,
pattern color=#1
},
font=\small\sffamily
]
\node[Node=44mm, Pattern=red!30] {desired pattern color: red};
\node[Node=44mm, Pattern=cyan!30] {desired pattern color: cyan};
\node[Node=44mm] {without pattern};
\node[Node=44mm, Pattern=orange!30] {desired pattern color: orange};
\end{tikzpicture}
\end{document}