
다음 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
해결책은 아니지만 진단은 다음과 같습니다.
양식 전용 패턴의 코드는 다음과 같습니다.~ 아니다색상 코드를 전혀 포함하지 마십시오. 따라서 문서를 믿는다면 정의 내에서 색상을 설정하는 것은 확실히 아니오입니다.
하지만 그렇게 하면 모든 것이 흑백으로 변할 뿐입니다...
좋아요. 패턴 매뉴얼 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}