我在谷歌上搜索了好久,也没找到这个答案。唯一接近我想要的是这个问题但我不太明白答案。它到底是如何\pgfarrowsdeclarecombine
工作的?
无论如何,我想在 TikZ 图片中制作一个看起来像的箭头+---->
。像普通箭头一样,但开头有一个加号。
答案1
这是一个非常简单的解决方案,可以根据线宽进行缩放:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\tikzset{+ /.tip = {Bar[sep=1.5pt 2,width=3pt 4]_[sep=0]}}
\begin{document}
\tikz\draw[+->] (0,0) -- (1,0);
\tikz[very thin]\draw[+->] (0,0) -- (1,0);
\tikz[very thick]\draw[+->] (0,0) -- (1,0);
\end{document}
答案2
这是一个“新风格”arrows.meta
版本...
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[+/.tip = {%
.
_[sep=2pt 2]% Comment out this line for no gap between the line and the +
Bar[sep=-1.5pt -2, length=0pt 1, width=3pt 3]
Bar[sep=0pt 0, length=3pt 3,width=0pt 1]
}]
\foreach \i in {1,...,10}
\draw [line width=\i/10, +-Stealth] (0,\i/2) -- +(1,0);
\end{tikzpicture}
\end{document}
...和一个“旧式”箭头版本(旧方法已被弃用并且不如新arrows.meta
方法灵活 - 但仍然有效并且创建起来更简单一些):
\documentclass[tikz,border=5]{standalone}
\makeatletter
\pgfarrowsdeclare{plus}{plus}
{
\pgfutil@tempdima=1pt%
\advance\pgfutil@tempdima by1.25\pgflinewidth
\pgfarrowsleftextend{+0pt}
\pgfarrowsrightextend{+3\pgfutil@tempdima}
}
{
\pgfutil@tempdima=1pt%
\advance\pgfutil@tempdima by1.25\pgflinewidth%
\pgfsetdash{}{+0pt}
\pgfsetmiterjoin
\pgfsetbuttcap
\pgfpathmoveto{\pgfqpoint{2.0\pgfutil@tempdima}{-1\pgfutil@tempdima}}
\pgfpathlineto{\pgfqpoint{2.0\pgfutil@tempdima}{\pgfutil@tempdima}}
\pgfpathmoveto{\pgfqpoint{1.0\pgfutil@tempdima}{0pt}}
\pgfpathlineto{\pgfqpoint{3.0\pgfutil@tempdima}{0pt}}
\pgfusepathqstroke
}
\pgfdeclarearrow{name=+-+, means=plus}
\begin{document}
\begin{tikzpicture}[]
\foreach \i in {1,...,10}
\draw [line width=\i/10, +-stealth] (0, \i/2) -- +(1,0);
\end{tikzpicture}
\end{document}