Tikzset con más de un valor predeterminado

Tikzset con más de un valor predeterminado
\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}

(Soy consciente de que ya se han hecho preguntas similares).

Para tratar más de un argumento, creo que necesito tener pgfkeys, pero todavía estoy confundido (por ejemplo, en el ejemplo anterior, las cosas están algo anidadas). ¿Existe un tutorial sencillo al respecto? ¿O alguien puede explicar paso a paso el caso anterior? (Eso es crear tantas claves como pueda necesitar cambiar mientras lo uso (como el ancho de la línea de flecha, el tipo de flecha, la longitud, el ancho, etc.).)

Respuesta1

Como preguntas sobre un tutorial, respondo la pregunta en dos pasos. (En mi humilde opinión, el pgfmanual es un excelente tutorial, en particular cuando lo usas para comprender los ejemplos que puedes encontrar en este sitio).poderhacer que un estilo dependa de varios parámetros. Pero siempre deberá especificarlos todos si desea cambiar solo uno. Por lo tanto, me gustaría argumentar que es más fácil almacenar los parámetros en pgfkeys con el valor predeterminado. Esto lleva 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}

ingrese la descripción de la imagen aquí

Por supuesto, en un momento dado puedes decidir que no quieres escribir siempre parallelone arrowantes type, lengthy así sucesivamente. Para eso están las familias clave. Entonces sólo podrá decir \draw[parallelone={type=Stealth}]si desea cambiar el tipo y dejar todo lo demás en sus valores predeterminados.

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

ingrese la descripción de la imagen aquí

Si quieres dos flechas con la misma funcionalidad, puedes probar

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

ingrese la descripción de la imagen aquí

información relacionada