
Por que no seguinte MWE, em todas as formas, a cor do padrão é igual ao primeiro, independentemente de ser definido de forma diferente?
%%%% 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}
Responder1
Este é um bug no \pgfcorepatterns.code.tex
. A macro interna \pgf@declarepatternmutable
salva o tipo de padrão como 7
em vez de #7
. A linha corrigida deve ser:
\expandafter\gdef\csname pgf@pattern@type@#1\endcsname{#7}%
Com essa mudança, os padrões funcionam conforme o esperado.
Responder2
Aqui está um diagnóstico, embora não uma solução.
O código para um padrão somente de formulário devenãoinclua o código de cores. Portanto, definir a cor dentro da definição é certamente proibido, se quisermos acreditar na documentação.
No entanto, isso apenas torna tudo preto ou branco...
OK. Comece com o código da página 1064 do manual do stars
padrão. Isso funciona bem, conforme anunciado:
Agora adicione suas variáveis para que tenhamos:
\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}
Tudo está menos bem:
Então não funciona como anunciado...
Há outra pergunta sobre o código nesta parte do manual que não funciona. Vou ver se encontro (eu perguntei). Não é o mesmo problema, mas talvez forneça uma pista.
EDITAR
Não é que seja impossível mudar a cor...
\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}