
¿Por qué en el siguiente MWE en todas las formas el color del patrón es como en el primero independientemente de que esté definido de manera 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}
Respuesta1
Este es un error en \pgfcorepatterns.code.tex
. La macro interna \pgf@declarepatternmutable
guarda el tipo de patrón como 7
en lugar de #7
. La línea corregida debería decir:
\expandafter\gdef\csname pgf@pattern@type@#1\endcsname{#7}%
Con este cambio los patrones funcionan como se esperaba.
Respuesta2
Aquí hay un diagnóstico, aunque no una solución.
El código para un patrón de solo formulario debenoincluir código de color en absoluto. Por lo tanto, establecer el color dentro de la definición es seguramente un no-no, si hay que creer en la documentación.
Sin embargo, eso simplemente vuelve todo blanco o negro...
DE ACUERDO. Comience con el código de la página 1064 del manual del stars
patrón. Esto funciona bien, como se anuncia:
Ahora agregue sus variables para que tengamos:
\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}
Todo está menos bien:
Entonces no funciona como se anuncia...
Hay otra pregunta sobre el código en esta parte del manual que no funciona. A ver si lo encuentro (lo pregunté). No es el mismo problema, pero tal vez proporcione una pista.
EDITAR
No es que sea imposible cambiar el color...
\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}