假设我的tikzset
定义包括:
vector/.style={%
decoration={markings, mark= at position 0.5 with {\arrow{Triangle[length=2.5mm, width=2mm]}}}, postaction={decorate}
},
假设我需要在其他地方使用相同的箭头样式。我该如何定义一些箭头样式并在以后引用它?类似于(不起作用):
\tikzset{%
myarrow/.style={
\arrow{Triangle[length=2.5mm, width=2mm]}
},
vector/.style={%
decoration={markings, mark= at position 0.5 with {myarrow}}, postaction={decorate}
},
}
答案1
使用密钥处理程序/.tip
:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,decorations.markings}
\tikzset{
myarrow/.tip={Triangle[length=2.5mm, width=2mm]},
vector/.style={
decoration={markings, mark= at position 0.5 with {\arrow{myarrow}}}
},
}
\begin{document}
\begin{tikzpicture}
\draw[-myarrow](0,0)--(2,0);
\draw[myarrow-{myarrow[red]}](0,-.25)--+(2,0);
\draw[postaction={vector,decorate}](0,-.5)--+(2,0);
\end{tikzpicture}
\end{document}