
\node
in 의 사용을 테스트하기 위해 다음 코드를 만듭니다 tikz
. 다른 경로(이 예에서는 /a)에 정의된 스타일을 사용하면 문제가 발생할 수 있습니다. 자세한 내용은 MWE를 참조하세요. 누구든지 원인과 처리 방법을 알려줄 수 있습니까?
MWE:
\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}
\pgfkeys{/a/.search also={/tikz},
/a/.cd,
myshape/.style={fill=red,circle},
size/.style={minimum size=#1*0.5cm},
size/.default=1
}
% example No.1:
\tikz\node[fill=red,circle]{AAA}; %The option "circle" can be used dirctly in "\node".
% example No.2:
% Contrasted with example No.1, why can "circle" not be used in myshape/.style which leads to unsuccessful compile?
% \tikz[/tikz/.search also={/a}]\node[myshape]{AAA};
% example No.3:
% Why does the "size=3" not work?
\tikz[/tikz/.search also={/a}]\node[fill=red,size=3]{AAA};
\end{document}
답변1
왜 작동하는지 묻고 있습니다 circle
. 이에 대한 대답은 실제로 약간 미묘하며 다음 코드 블록에 포함되어 있습니다 tikz.code.tex
.
\pgfkeys{/tikz/.unknown/.code=%
% Is it a pgf key?
\let\tikz@key\pgfkeyscurrentname%
\pgfkeys{/pgf/\tikz@key/.try={#1}}%
\ifpgfkeyssuccess%
\else%
\expandafter\pgfutil@in@\expandafter!\expandafter{\tikz@key}%
\ifpgfutil@in@%
% this is a color!
\expandafter\tikz@addoption\expandafter{\expandafter\tikz@compat@color@set\expandafter{\tikz@key}}%
\edef\tikz@textcolor{\tikz@key}%
\else%
\pgfutil@doifcolorelse{\tikz@key}
{%
\expandafter\tikz@addoption\expandafter{\expandafter\tikz@compat@color@set\expandafter{\tikz@key}}%
\edef\tikz@textcolor{\tikz@key}%
}%
{%
% Ok, second chance: This might be an arrow specification:
\expandafter\pgfutil@in@\expandafter-\expandafter{\tikz@key}%
\ifpgfutil@in@%
% Ah, an arrow spec!
\expandafter\tikz@processarrows\expandafter{\tikz@key}%
\else%
% Ok, third chance: A shape!
\expandafter\ifx\csname pgf@sh@s@\tikz@key\endcsname\relax%
\pgfkeys{/errors/unknown key/.expand
once=\expandafter{\expandafter/\expandafter t\expandafter i\expandafter k\expandafter z\expandafter/\tikz@key}{#1}}%
\else%
\edef\tikz@shape{\tikz@key}%
\fi%
\fi%
}%
\fi%
\fi%
}%
보시다시피 티케이Z는 온갖 것을 시도합니다. 이는 circle
대신 shape=circle
및 red
대신 말할 수 있기 때문에 사용자에게 편리합니다 color=red
.
코드를 /.try
. 그러나 나는 이것을 권장하지 않습니다. 오히려 그냥 Ti 주는 걸 추천드려요케이shape=circle
Z 정보의 누락된 부분, 즉 대신 circle
및 /pgf/minimum size
대신에 말하기 minimum size
.
\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}
\pgfkeys{/a/.search also={/tikz},
/a/.cd,
myshape/.style={fill=red,shape=circle},
size/.style={/pgf/minimum size=#1*0.5cm},
size/.default=1
}
% example No.1:
\tikz\node[fill=red,circle]{AAA}; %The option "circle" can be used dirctly in "\node".
% example No.2:
% Contrasted with example No.1, why can "circle" not be used in myshape/.style which leads to unsuccessful compile?
\tikz[/tikz/.search also={/a}]\node[myshape]{AAA};
% example No.3:
% Why does the "size=3" not work?
\tikz[/tikz/.search also={/a}]\node[fill=red,size=3]{AAA};
\end{document}
내가 이것을 추천하는 이유는 /.try
너무 많은 일을 하게 되면 어떤 키가 우선순위인지가 점점 더 명확해지기 때문입니다.