tikz
我讨厌或中的预定义箭头样式pgfplots
,并设法tikz
通过使用装饰在中应用自定义箭头。现在我尝试在中应用相同的装饰代码,pgfplots
axis
但失败并出现神秘错误。
我找到了这个答案:https://tex.stackexchange.com/a/51584/75284具体来说是将装饰应用于pgfplots
轴线,它可以为我编译,但是插入\fill
我需要的箭头命令并删除该\arrow
命令时,编译就会挂起:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows, decorations,decorations.markings}
\tikzset{ % this is the arrow style I want
myarrow/.style={decoration={markings, mark=at position 1 with {
\fill(-0.3,-0.05) -- (0,0) -- (-0.3,0.05) -- cycle;
}}, postaction={decorate},shorten >=5 pt}
}
\makeatletter
\tikzset{
nomorepostaction/.code=\makeatletter\let\tikz@postactions\pgfutil@empty, % From https://tex.stackexchange.com/questions/3184/applying-a-postaction-to-every-path-in-tikz/5354#5354
my axis/.style={
postaction={
decoration={
markings,
mark=at position 1 with {
\arrow[ultra thick]{latex} % this works
%\fill(-0.3,-0.05) -- (0,0) -- (-0.3,0.05) -- cycle; % this is just the \fill command pasted in
}
},
decorate,
nomorepostaction
},
thin,
-, % switch off other arrow tips
every path/.append style=my axis % this is necessary so it works both with "axis lines=left" and "axis lines=middle"
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
axis line style={my axis}
]
\addplot coordinates {(-0.1,-0.2) (1.2,1.2)};
\end{axis}
\draw[myarrow] (0,0) -- (3,5);
\end{tikzpicture}
\end{document}
不过,这只是我的尝试。我欢迎任何关于如何在pgfplots
轴线中使用完全可自定义的箭头的解决方案。例如,如果有办法将\draw
命令箭头线放置在正确的位置,它也会起作用。
答案1
我用 解决了我的问题arrows.meta
,过去几年我不知何故完全错过了这个问题。
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\tikzset{
myarrow/.style={-{Triangle[length=3mm,width=1mm]}}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
axis line style={myarrow}
]
\addplot coordinates {(-0.1,-0.2) (1.2,1.2)};
\end{axis}
\draw[myarrow] (0,0) -- (1,5.5);
\end{tikzpicture}
\end{document}