이 예제는 실제로 필요한 것보다 훨씬 길지만 지금은 정리할 시간이 없습니다(죄송합니다!).
이 예제의 모든 내용은 예상대로 작동합니다.제외하고my fill
키로 정의되어야 하는 키 입니다 .is choice
. 그러나 컴파일하려고 하면 LaTeX에서 다음과 같이 불평합니다.
! Package pgfkeys Error: I do not know the key '/tikz/my fill=blue' and I am go
ing to ignore it. Perhaps you misspelled it.
my fill=<color>
각 항목을 로 바꾸면 my <color>
코드가 올바르게 컴파일됩니다.
%-*-mode:LaTeX-*-
\documentclass[border=8]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}
\usepackage{etoolbox}
\let\x\expandafter
\makeatletter
%-@-(1)---------------------------------------------------------------------
\long\def\if@node@defined(#1)#2#3{%%
\@ifundefined{pgf@sh@ns@#1}%%
{#3}%% FALSE: "yes" it's undefined
{#2}}% TRUE: "no" it's not undefined
\def\ifsquarenodedefined#1{%%
\x\let\x\ae@tmp\csname ae@#1@node\endcsname
\x\if@node@defined\x(\ae@tmp){\booltrue{#1.bool}}{\boolfalse{#1.bool}}}
\providebool{nw.bool}
\providebool{ne.bool}
\providebool{sw.bool}
\providebool{se.bool}
%-@-(2)---------------------------------------------------------------------
%% First call the function to read the "optional" arguments, which really
%% aren't so optional. The optional arguments should be passed as
%% [#1;#2;#3] where #1 is actually required.
\newcommand\aesquare{\ae@square}
%% #1=nw,ne,se,sw ==> set the right angle for the triangle to be colored
%% #2=sets the optional arguments to be passed to the draw command.
%% #3=sets the optional arguments to be passed to the fill command.
\def\ae@square[#1;#2;#3]{%%
\def\@@ae@corner{#1}%%
\def\@@ae@draw{#2}%%
\def\@@ae@fill{#3}
\@ae@square}
%% This next macro is the meat of the business. It will only draw and fill
%% the triangle defined by the passed nodes if, in fact, the nodes are
%% already defined.
\def\@ae@square(#1,#2,#3){%%
%%
\pgfmathsetmacro\ae@node@nx{int(#2+1)}%%
\pgfmathsetmacro\ae@node@ny{int(#3-1)}%%
%% set the macros that `\ifsquarenodedefined` expects to already be
%% defined.
\edef\ae@nw@node{A#2#3}%%
\edef\ae@ne@node{A\ae@node@nx#3}%%
\edef\ae@se@node{A\ae@node@nx\ae@node@ny}%%
\edef\ae@sw@node{A#2\ae@node@ny}%%
%% set the booleans that will be tested next.
\ifsquarenodedefined{nw}%%
\ifsquarenodedefined{ne}%%
\ifsquarenodedefined{se}%%
\ifsquarenodedefined{sw}%%
%% only draw and fill a triangle if the corners are all properly defined.
\ifboolexpr{
bool {nw.bool} and
bool {ne.bool} and
bool {se.bool} and
bool {sw.bool} }
{
\x\ifstrequal\x{\@@ae@corner}{nw}{\ae@set{a}{sw}\ae@set{b}{nw}\ae@set{c}{ne}}{}
\x\ifstrequal\x{\@@ae@corner}{ne}{\ae@set{a}{nw}\ae@set{b}{ne}\ae@set{c}{se}}{}
\x\ifstrequal\x{\@@ae@corner}{se}{\ae@set{a}{ne}\ae@set{b}{se}\ae@set{c}{sw}}{}
\x\ifstrequal\x{\@@ae@corner}{sw}{\ae@set{a}{se}\ae@set{b}{sw}\ae@set{c}{nw}}{}
\draw[\@@ae@draw] (\ae@a) -- (\ae@b) -- (\ae@c) -- cycle;
\fill[\@@ae@fill] (\ae@a) -- (\ae@b) -- (\ae@c) -- cycle;
}{}}
\def\ae@set#1#2{%%
\x\edef\csname ae@#1\endcsname{\csname ae@#2@node\endcsname}}
\makeatother
\begin{document}%%'
\begin{tikzpicture}[my dot/.style={fill,circle,inner sep=1.5pt},>={To[scale=2]},
my colors/.style={
my gray/.style={gray},
my blue/.style={blue!30},
my red/.style={red},
my green/.style={green},
},
my same colors/.style={
my gray/.style={gray},
my blue/.style={gray},
my red/.style={gray},
my green/.style={gray},
},
my fill/.is choice,
my fill/blue/.style={my blue},
my fill/gray/.style={my gray},
my fill/red/.style={my red},
my fill/green/.style={my green},
my draw/.style={line width=0.8pt},
my colors,
x=1.5cm,y=1.5cm
]
\coordinate (A11) at (0,0);
\foreach \myx in {0,...,6}
{
\foreach \myy in {0,...,6}
{
\coordinate (A\myx\myy) at (\myx,\myy);
}
}
\foreach \myx in {0,...,6}
{
\foreach \myy in {0,...,6}
{
\pgfmathsetmacro\aeinta{int(\myx)}%%
\pgfmathsetmacro\aeintb{int(\myy)}%%
\ifnumcomp{\aeinta}{<}{3}
{
\ifnumcomp{\aeintb}{<}{4}
{
\aesquare[ne;my draw;my fill=blue](A,\myx,\myy)
}
{
\aesquare[se;my draw;my fill=red](A,\myx,\myy)
}
}
{
\ifnumcomp{\aeintb}{<}{4}
{
\aesquare[nw;my draw;my fill=green](A,\myx,\myy)
}
{
\aesquare[sw;my draw;my fill=gray](A,\myx,\myy)
}
}
}
}
\draw[my draw] (A00) rectangle (A66);
\end{tikzpicture}
\end{document}%%'
누군가 내가 선택한 키가 올바르게 작동하도록 하는 방법을 설명해 줄 수 있습니까?
제대로 작동하고 키를 my colors
선택하면 결과는 다음과 같아야 합니다.
답변1
.is choice
귀하의 문제는 (에서 사용됨 ) 과 관련이 없습니다 my fill=blue
. 에서도 동일한 오류가 발생합니다 fill=blue
. 귀하의 문제는 pgfkey에 의한 매크로 확장과 관련이 있습니다. pgfkey는 값이 있는 my flll=blue
키가 아니라 키를 봅니다 .my fill
blue
첫 번째 해결 방법:
바꾸다 :
\fill[\@@ae@fill]...
에 의해:
\expandafter\fill\expandafter[\@@ae@fill]...
두 번째 해결 방법:
바꾸다:
\def\@@ae@fill{#3}
에 의해:
\tikzset{@@ae@fill/.style={#3}}
그런 다음 다음을 교체하십시오.
\fill[\@@ae@fill]...
에 의해:
\fill[@@ae@fill]...