TikZ/pgfkeys를 사용하여 키와 값 변경

TikZ/pgfkeys를 사용하여 키와 값 변경

또 다른 TikZ 문제: 두 벡터 모두 플롯되었지만 두 번째 벡터에서는 오류가 발생합니다.

! Dimension too large.
<to be read again> 
              \relax 
l.37   \myvector[text align=center](1,1)
                                    ;
I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.

벡터가 작으면 정렬에 문제가 있을 수 있다는 것을 이해합니다. 하지만 텍스트가 없어도 오류가 발생합니다.

그래서 테스트해 보았습니다.

\ifx\mbftex\empty \def\mbfdecoration{} \else \mbfdecoration{postaction={decorate,decoration={text along path,text align/.expand once=\mbftextalign,text=\mbftext,raise=\mbfraise}}}} /fi

다음과 같이 사용하십시오.

\centerarct[draw=\mbfcolor,line  width=\mbflinewidth,\mbfdecoration](#2)(20:21:\mbfradius);

하지만 이것은 작동하지 않습니다. 좋아, 텍스트가 비어 있는지 여부에 따라 centerarc에 대한 두 가지 정의를 만들 수 있습니다. 하지만 다른 방법이 있나요? 나는 tikzset과 스타일을 사용하여 솔루션을 얻으려고 노력했지만 이 역시 효과가 없었습니다.

\documentclass[10pt]{article}
\usepackage[a4paper,top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta,bending,decorations.text,positioning}

\def\centerarct[#1](#2)(#3:#4:#5)% Syntax: [draw options] (center) (start angle:end angle:radius)
{ \path[#1] ($(#2)+({#5*cos(-#3+90)},{#5*sin(-#3+90)})$) arc [start angle={-#3+90}, end angle={-#4+90}, radius=#5)]; }

\pgfkeys{
    myvector/.is family,
    myvector,
    radius/.initial=4cm,
    line width/.initial =5mm,
    color/.initial=orange,
    text align/.initial=right,
    text/.initial=,
    raise/.initial=0mm
}

\newcommand\myvectorset[1]{\pgfkeys{myvector,#1}}

\def\myvector[#1](#2){
    \myvectorset{#1,
    radius/.get=\mbfradius,
    line width/.get=\mbflinewidth,
    color/.get=\mbfcolor,
    text align/.get=\mbftextalign,
    text/.get=\mbftext,
    raise/.get=\mbfraise
}
\centerarct[draw=\mbfcolor,line  width=\mbflinewidth,postaction={decorate,decoration={text along path,text align/.expand once=\mbftextalign,text=\mbftext,raise=\mbfraise}}](#2)(20:21:\mbfradius);
}

\begin{document}
 \begin{tikzpicture}
  \myvector[](0,0);
  \myvector[text align=center](1,1);
 \end{tikzpicture}
\end{document}

다음과 같은 것을 구현하는 방법이 있습니까?

\documentclass[10pt]{article}
\usepackage[a4paper,top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta,bending,decorations.text,positioning}

\begin{document}
 \def\mytext{}
 %\ifx\mytext\empty {\def\mykey{draw=red}} \else {\def\mykey{draw=blue}} \fi % not-solved-1
 \begin{tikzpicture}
  \tikzset{mystyle/.style={draw=red}} works
  %\ifx\mytext\empty {\tikzset{mystyle/.style={draw=red}}} \else {\tikzset{mystyle/.style={draw=blue}}} \fi  % not-solved-2
  %\path[mykey] (0,0) -- (1,1); % part of not-solved-1
  \path[mystyle] (0,0) -- (1,1);
 \end{tikzpicture}
\end{document}

이것이 작동하기 때문에:

\begin{document}
 \def\mytext{}
 \begin{tikzpicture}
  \ifx \mytext \empty \def\mytest{red} \else \def\mytest{blue} \fi
  \path[draw=\mytest] (0,0) -- (2,1);
 \end{tikzpicture}
\end{document}

하지만 키와 그 값을 바꿔야 합니다.

관련 정보