둘 이상의 기본값을 가진 Tikzset

둘 이상의 기본값을 가진 Tikzset
\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}
\begin{document}

\tikzset{%
  parallelone/.style={%
    decoration={markings, mark= at position #1 with
    {\arrow[line width=0.5mm, stealth-]{Latex[length=2.5mm, width=2mm]}}},
    postaction={decorate}
  },
   parallelone/.default=0.5,
}

\begin{tikzpicture}
    \draw[parallelone] (0,0)--(4,4);
\end{tikzpicture}

\end{document}

(이미 유사한 질문을 받은 것으로 알고 있습니다.)

하나 이상의 인수를 처리하려면 가 있어야 한다고 생각 pgfkeys하지만 여전히 혼란스럽습니다(예를 들어 위의 예에서는 내용이 다소 중첩되어 있습니다). 이에 대한 간단한 튜토리얼이 있나요? 아니면 누군가 위 사례에 대해 단계별 설명을 제공할 수 있습니까? (즉, 사용하는 동안 변경해야 할 수 있는 만큼 많은 키를 생성합니다(예: 화살표 선 너비, 화살표 유형, 길이, 너비 등).)

답변1

튜토리얼에 대해 질문하셨기 때문에 두 단계로 질문에 답하겠습니다. (IMHO pgfmanual은 특히 이 사이트에서 찾을 수 있는 예제를 이해하는 데 사용할 때 훌륭한 튜토리얼입니다.)~할 수 있다여러 매개변수에 따라 스타일을 결정합니다. 하지만 하나만 변경하려면 항상 모든 항목을 지정해야 합니다. 따라서 기본값을 사용하여 pgfkeys에 매개변수를 저장하는 것이 더 쉽다고 주장하고 싶습니다. 이로 인해

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}
\begin{document}

\tikzset{%
  parallelone arrow length/.initial=2.5mm,
  parallelone arrow width/.initial=2mm,
  parallelone arrow type/.initial=Latex,
  parallelone/.style={%
    decoration={markings, mark= at position #1 with
    {\arrow{\pgfkeysvalueof{/tikz/parallelone arrow type}[length=\pgfkeysvalueof{/tikz/parallelone arrow length}, 
    width=\pgfkeysvalueof{/tikz/parallelone arrow width}]}}},
    postaction={decorate}
  },
   parallelone/.default=0.5
}

\begin{tikzpicture}
    \draw[parallelone] (0,0)--(4,4);    
    % change the length and poisition
    \draw[parallelone=0.7,parallelone arrow length=5mm] (1,0)--(5,4);
    % change the type. the length is back to its initial or default values
    \draw[parallelone,parallelone arrow type=Stealth] (2,0)--(6,4);
    % change the width. the other paraneters are at their initial or deault values
    \draw[parallelone,parallelone arrow width=5mm] (3,0)--(7,4);    
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

물론 특정 시점에서 항상 parallelone arrow앞에 입력하고 싶지 않다고 결정할 수도 있습니다 type. length이것이 주요 가족의 목적입니다. 그런 다음 \draw[parallelone={type=Stealth}]유형을 변경하고 다른 모든 항목은 기본값으로 두려는 경우 에만 말할 수 있습니다 .

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}
\begin{document}

\tikzset{%
  parallelone/.style={%
    /utils/exec=\tikzset{parallelone arrow/.cd,#1},
    decoration={markings, mark= at position \pgfkeysvalueof{/tikz/parallelone arrow/pos} with
    {\arrow{\pgfkeysvalueof{/tikz/parallelone arrow/type}[%
    length=\pgfkeysvalueof{/tikz/parallelone arrow/length},%
    width=\pgfkeysvalueof{/tikz/parallelone arrow/width}]}}},
    postaction={decorate}
  },
  parallelone/.default={pos=0.5},
  parallelone arrow/.is family,
  parallelone arrow/.cd,
  pos/.initial=0.5,
  length/.initial=2.5mm,
  width/.initial=2mm,
  type/.initial=Latex,
}

\begin{tikzpicture}
    \draw[parallelone] (0,0)--(4,4);    
    % change the length and poisition
    \draw[parallelone={pos=0.7,length=5mm}] (1,0)--(5,4);
    % change the type. the length is back to its initial or default values
    \draw[parallelone={type=Stealth}] (2,0)--(6,4);
    % change the width. the other parameters are at their initial or deault values
    \draw[parallelone={width=5mm}] (3,0)--(7,4);    
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

동일한 기능을 가진 두 개의 화살표를 원한다면 시도해 볼 수 있습니다

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}
\begin{document}

\tikzset{%
  parallelone/.style={%
    /utils/exec=\tikzset{parallelone arrow/.cd,#1},
    decoration={markings, mark= at position \pgfkeysvalueof{/tikz/parallelone arrow/pos} with
    {\arrow{\pgfkeysvalueof{/tikz/parallelone arrow/type}[%
    length=\pgfkeysvalueof{/tikz/parallelone arrow/length},%
    width=\pgfkeysvalueof{/tikz/parallelone arrow/width}]}}},
    postaction={decorate}
  },
  paralleltwo/.style={%
    /utils/exec=\tikzset{parallelone arrow/.cd,#1},
    decoration={markings, mark= at position \pgfkeysvalueof{/tikz/parallelone arrow/pos} with
    {\arrow{\pgfkeysvalueof{/tikz/parallelone arrow/type}[%
    length=\pgfkeysvalueof{/tikz/parallelone arrow/length},%
    width=\pgfkeysvalueof{/tikz/parallelone arrow/width}]%
    \pgfkeysvalueof{/tikz/parallelone arrow/type}[%
    length=\pgfkeysvalueof{/tikz/parallelone arrow/length},%
    width=\pgfkeysvalueof{/tikz/parallelone arrow/width}]}}},
    postaction={decorate}
  },
  parallelone/.default={pos=0.5},
  parallelone arrow/.is family,
  parallelone arrow/.cd,
  pos/.initial=0.5,
  length/.initial=2.5mm,
  width/.initial=2mm,
  type/.initial=Latex,
}

\begin{tikzpicture}
    \draw[paralleltwo] (0,0)--(4,4);    
    % change the length and poisition
    \draw[parallelone={pos=0.7,length=5mm}] (1,0)--(5,4);
    % change the type. the length is back to its initial or default values
    \draw[parallelone={type=Stealth}] (2,0)--(6,4);
    % change the width. the other parameters are at their initial or deault values
    \draw[parallelone={width=5mm}] (3,0)--(7,4);    
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보