使用 TikZ/PGF 制作部分三角箭头

使用 TikZ/PGF 制作部分三角箭头

我想绘制一个部分箭头(即只有“一半”的尖端),但尖端形状为三角形(例如使用> = latex),而不是使用“从左到右”等获得的标准单线。

结果应该类似于下面的图像:

三角形部分箭头

我该如何实现这一点?我在 TikZ/PGF 手册中没有看到任何这样的提示。

答案1

新的真的很酷CVS arrow stuff(弯曲的箭头!)由 Till Tantau 编写,可以对箭头进行各种自定义。特别是left箭头right的各个部分可以像这样指定-{Stealth[left]}

此示例摘自最新的 CVS 手册:

\documentclass[border=0.125cm]{standalone}

\usepackage{tikz}

\usetikzlibrary{arrows.meta}

\makeatletter
\long\def\arrowexample#1{%
    \tt#1 &
    \tikz\draw [-{#1}, very thick](0,0) -- (1,0);
    \\
}
\begin{document}

\begin{tabular}{ll}
    \arrowexample{Stealth[]}
    \arrowexample{Stealth[sep] Stealth[]}
    \arrowexample{Stealth[sep] . Stealth[]}
    \arrowexample{Stealth[open]}
    \arrowexample{Stealth[length=6pt,width=4pt]}
    \arrowexample{Stealth[length=6pt,width=4pt,inset=1.5pt]}
    \arrowexample{Stealth[round]}
    \arrowexample{Stealth[slant=.3]}
    \arrowexample{Stealth[left]}
    \arrowexample{Stealth[right]}
    \arrowexample{Stealth[red]}
\end{tabular}

\end{document}

在此处输入图片描述

答案2

路易吉,意大利论坛中提供的 TikZ-arrows 大师与这个问题非常接近的东西(用于隐身提示)。

在此基础上:

\documentclass[tikz,border=10pt]{standalone}

\usepackage{tikz}

\makeatletter
\pgfarrowsdeclare{left stealth}{left stealth}
{
  \pgfutil@tempdima=0.28pt%
  \pgfutil@tempdimb=\pgflinewidth%
  \ifdim\pgfinnerlinewidth>0pt%
    \pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
  \fi%
  \advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
  \pgfarrowsleftextend{+-3\pgfutil@tempdima}
  \pgfarrowsrightextend{+5\pgfutil@tempdima}
}
{
  \pgfutil@tempdima=0.28pt%
  \pgfutil@tempdimb=\pgflinewidth%
  \ifdim\pgfinnerlinewidth>0pt%
    \pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
  \fi%
  \advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
  \pgfmathsetlength\pgfutil@tempdimb{5\pgfutil@tempdima-\pgflinewidth}
  \pgfpathmoveto{\pgfqpoint{5\pgfutil@tempdima}{0pt}}
  \pgfpathlineto{\pgfqpoint{-3\pgfutil@tempdima}{4\pgfutil@tempdima}}
  \pgfpathlineto{\pgfpointorigin}
  \pgfpathlineto{\pgfqpoint{0pt}{-.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{\pgfutil@tempdimb}{-.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{6\pgfutil@tempdima}{-0.5\pgflinewidth}}
  \pgfusepathqfill
}

\pgfarrowsdeclare{right stealth}{right stealth}
{
  \pgfutil@tempdima=0.28pt%
  \pgfutil@tempdimb=\pgflinewidth%
  \ifdim\pgfinnerlinewidth>0pt%
    \pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
  \fi%
  \advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
  \pgfarrowsleftextend{+-3\pgfutil@tempdima}
  \pgfarrowsrightextend{+5\pgfutil@tempdima}
}
{
  \pgfutil@tempdima=0.28pt%
  \pgfutil@tempdimb=\pgflinewidth%
  \ifdim\pgfinnerlinewidth>0pt%
    \pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
  \fi%
  \advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
  \pgfmathsetlength\pgfutil@tempdimb{5\[email protected]\pgflinewidth}
  \pgfpathmoveto{\pgfqpoint{5\pgfutil@tempdima}{0pt}}
  \pgfpathlineto{\pgfqpoint{-3\pgfutil@tempdima}{-4\pgfutil@tempdima}}
  \pgfpathlineto{\pgfpointorigin}
  \pgfpathlineto{\pgfqpoint{0pt}{.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{\pgfutil@tempdimb}{0.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{6\pgfutil@tempdima}{0.5\pgflinewidth}}
  \pgfusepathqfill
}

\pgfarrowsdeclare{left triangle}{left triangle}
{
  \pgfutil@tempdima=0.28pt%
  \pgfutil@tempdimb=\pgflinewidth%
  \ifdim\pgfinnerlinewidth>0pt%
    \pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
  \fi%
  \advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
  \pgfarrowsleftextend{+-3\pgfutil@tempdima}
  \pgfarrowsrightextend{+5\pgfutil@tempdima}
}
{
  \pgfutil@tempdima=0.28pt%
  \pgfutil@tempdimb=\pgflinewidth%
  \ifdim\pgfinnerlinewidth>0pt%
    \pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
  \fi%
  \advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
  \pgfmathsetlength\pgfutil@tempdimb{5\pgfutil@tempdima-\pgflinewidth}
  \pgfpathmoveto{\pgfqpoint{5\pgfutil@tempdima}{0pt}}
  \pgfpathlineto{\pgfqpoint{0pt}{4\pgfutil@tempdima}}
  \pgfpathlineto{\pgfpointorigin}
  \pgfpathlineto{\pgfqpoint{0pt}{-.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{\pgfutil@tempdimb}{-.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{5.5\pgfutil@tempdima}{-0.5\pgflinewidth}}
  \pgfusepathqfill
}

\pgfarrowsdeclare{right triangle}{right triangle}
{
  \pgfutil@tempdima=0.28pt%
  \pgfutil@tempdimb=\pgflinewidth%
  \ifdim\pgfinnerlinewidth>0pt%
    \pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
  \fi%
  \advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
  \pgfarrowsleftextend{+-3\pgfutil@tempdima}
  \pgfarrowsrightextend{+5\pgfutil@tempdima}
}
{
  \pgfutil@tempdima=0.28pt%
  \pgfutil@tempdimb=\pgflinewidth%
  \ifdim\pgfinnerlinewidth>0pt%
    \pgfmathsetlength\pgfutil@tempdimb{.6\pgflinewidth-.4*\pgfinnerlinewidth}%
  \fi%
  \advance\pgfutil@tempdima by.3\pgfutil@tempdimb%
  \pgfmathsetlength\pgfutil@tempdimb{5\[email protected]\pgflinewidth}
  \pgfpathmoveto{\pgfqpoint{5\pgfutil@tempdima}{0pt}}
  \pgfpathlineto{\pgfqpoint{0pt}{-4\pgfutil@tempdima}}
  \pgfpathlineto{\pgfpointorigin}
  \pgfpathlineto{\pgfqpoint{0pt}{.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{\pgfutil@tempdimb}{0.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{5.5\pgfutil@tempdima}{0.5\pgflinewidth}}
  \pgfusepathqfill
}

\makeatother

\begin{document}

\begin{tikzpicture}
\draw[right stealth-right stealth]   (0,0)--(2,0);
\draw[left stealth-left stealth]     (0,1)--(2,1);
\draw[right triangle-right triangle] (0,2)--(2,2);
\draw[left triangle-left triangle]   (0,3)--(2,3);
\end{tikzpicture}
\end{document}

结果:

在此处输入图片描述

相关内容