Tikzset com mais de um padrão

Tikzset com mais de um padrão
\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}

(Estou ciente de que perguntas semelhantes já foram feitas.)

Para lidar com mais de um argumento, acho que preciso ter pgfkeys, mas ainda estou confuso (por exemplo, no exemplo acima, as coisas estão um tanto aninhadas). Existe um tutorial simples sobre isso? Ou alguém pode fornecer uma explicação passo a passo para o caso acima? (Isso é criar quantas chaves eu precisar alterar ao usá-lo (como largura da linha da seta, tipo de seta, comprimento, largura, etc.).)

Responder1

Como você está perguntando sobre um tutorial, respondo à pergunta em duas etapas. (IMHO, o pgfmanual é um excelente tutorial, principalmente quando você o usa para entender exemplos que pode encontrar neste site.) Vocêpodefazer um estilo depender de vários parâmetros. Mas então você sempre precisará especificar todos eles se quiser alterar apenas um. Portanto, gostaria de argumentar que é mais fácil armazenar os parâmetros em pgfkeys com valor padrão. Isto leva a

\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}

insira a descrição da imagem aqui

É claro que, em determinado momento, você pode decidir que não deseja digitar sempre parallelone arrowantes typee lengthassim por diante. É para isso que servem as famílias-chave. Então você só poderá dizer \draw[parallelone={type=Stealth}]se deseja alterar o tipo e deixar todo o resto com os valores padrão.

\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}

insira a descrição da imagem aqui

Se você quiser duas setas com a mesma funcionalidade, você pode tentar

\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}

insira a descrição da imagem aqui

informação relacionada