
\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}
(Mir ist bewusst, dass ähnliche Fragen bereits gestellt wurden.)
Um mit mehr als einem Argument umgehen zu können, muss ich meiner Meinung nach haben pgfkeys
, aber ich bin immer noch verwirrt (zum Beispiel sind die Dinge im obigen Beispiel etwas verschachtelt). Gibt es ein einfaches Tutorial dazu? Oder kann jemand eine Schritt-für-Schritt-Erklärung für den obigen Fall geben? (Das heißt, ich erstelle so viele Schlüssel, wie ich während der Verwendung ändern muss (wie Pfeillinienbreite, Pfeiltyp, Länge, Breite usw.).)
Antwort1
Da Sie nach einem Tutorial fragen, beantworte ich die Frage in zwei Schritten. (Meiner Meinung nach ist das pgfmanual ein hervorragendes Tutorial, insbesondere wenn Sie es verwenden, um Beispiele zu verstehen, die Sie auf dieser Site finden können.) Siedürfeneinen Stil von mehreren Parametern abhängig machen. Dann müssen Sie aber immer alle angeben, wenn Sie nur einen ändern möchten. Daher möchte ich argumentieren, dass es einfacher ist, die Parameter in pgfkeys mit Standardwerten zu speichern. Dies führt zu
\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}
Natürlich können Sie an einem bestimmten Punkt entscheiden, dass Sie nicht immer parallelone arrow
vor eingeben möchten type
usw. length
Dafür gibt es Schlüsselfamilien. Dann können Sie nur angeben, \draw[parallelone={type=Stealth}]
ob Sie den Typ ändern möchten, und alles andere auf den Standardwerten belassen.
\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}
Wenn Sie zwei Pfeile mit der gleichen Funktionalität wünschen, könnten Sie versuchen
\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}