我想用 tikz 画一个带条纹箭头的箭头。我在tikz 文档去做这个。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[very thick,font=\sffamily\Large]
\draw[-{Latex[length=30mm,angle'=10]}] (0,-2) -- (0,3);
\end{tikzpicture}
\end{document}
我想要制作类似下图的东西。带有箭头的黑线,其上有均匀分布的橙色/白色条纹:
答案1
用inset
错了,它表示条纹的数量(包括白色/透明条纹)。偶数表示线条以白色条纹结束。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, bending}
\pgfdeclarearrow{
name = Striped Triangle,
defaults = {
length = +3pt 4.5 .8,
width' = +0pt .75,
inset' = +13pt,
angle=+60:+2.7pt +3.6,
},
setup code={%
\pgfarrowssettipend{0pt}%
\pgfarrowssetbackend{-\pgfarrowlength}%
\pgfarrowssetlineend{\dimexpr-\pgfarrowlength+.001pt}% visual things
\pgfarrowsupperhullpoint{0pt}{0pt}%
\pgfarrowsupperhullpoint{-\pgfarrowlength}{.5\pgfarrowwidth}%
\pgfarrowssavethe\pgfarrowlength
\pgfarrowssavethe\pgfarrowwidth
\pgfarrowssavethe\pgfarrowinset
\pgfmathreciprocal{\pgfarrowinset}%
\let\pgfarrowstripedtrianglefrac\pgfmathresult
\pgfarrowssave\pgfarrowstripedtrianglefrac
},
drawing code={%
\pgfmathloop % could use qicker \pgfmathmultiply@ here
\pgfmathmultiply{\pgfmathcounter-1}{\pgfarrowstripedtrianglefrac}\let\near\pgfmathresult
\ifdim\pgfmathcounter pt=\pgfarrowinset \def\far{1}% just use 1 instead of n*1/n
\else
\pgfmathmultiply{\pgfmathcounter}{\pgfarrowstripedtrianglefrac}\let\far\pgfmathresult
\fi
\pgfpathmoveto{\pgfqpointscale{\near}{\pgfqpoint{-\pgfarrowlength}{+.5\pgfarrowwidth}}}%
\pgfpathlineto{\pgfqpointscale{\far }{\pgfqpoint{-\pgfarrowlength}{+.5\pgfarrowwidth}}}%
\pgfpathlineto{\pgfqpointscale{\far }{\pgfqpoint{-\pgfarrowlength}{-.5\pgfarrowwidth}}}%
\pgfpathlineto{\pgfqpointscale{\near}{\pgfqpoint{-\pgfarrowlength}{-.5\pgfarrowwidth}}}%
\pgfpathclose
\ifdim\pgfinteval{1+\pgfmathcounter}pt<\pgfarrowinset\relax
\edef\pgfmathcounter{\pgfinteval{\pgfmathcounter+1}}%
\repeatpgfmathloop
\pgfusepathqfill
},
parameters={\the\pgfarrowlength,\the\pgfarrowwidth,\the\pgfarrowinset}
}
\tikzset{>={Striped Triangle[fill=orange, angle'=30]}}
\begin{document}
\begin{tikzpicture}[ultra thick]
\foreach[count=\i] \ang in {0, 30, ..., 359}
\draw[-{>[inset=2*\i-1]}] (0,0) -- (\ang:.7);
\end{tikzpicture}
\begin{tikzpicture}
\foreach[count=\i] \bendmode in {quick, flex, bend}{
\tikzset{yshift=-\i cm}
\draw [red!25,line width=1mm] (-1,0) -- (1,0);
\draw [red,line width=1mm,-{[\bendmode]>.>>}]
(-1,-.5) node[right, black] {\bendmode}
.. controls (0,-.5) and (0,0) .. (1,0);
}
\end{tikzpicture}
\end{document}
输出
答案2
这是一个使用 decorations.markings 的选项,虽然它们可以改进以适应曲线,但在这种情况下它不能,但你可以寻找带有示例线圈,但是最好将其声明为样式或图片,这样您就可以用很少的代码做很多事情。
梅威瑟:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,decorations.markings,calc}
\definecolor{brown}{HTML}{2E2111}
\begin{document}
\begin{tikzpicture}[
%Environment Styles
MyArrow/.style={
draw,
shorten >=28pt,
line width=2pt,
preaction={
decorate,
shorten >=0pt,
line width=1pt,
rounded corners=0,
decoration={
markings,
mark=at position 1
with {
\clip[](0,0) -- ++(-28pt,-5pt) -- ++(0,10pt) -- cycle;
\fill[#1](0,0) -- ++(-28pt,-5pt) -- ++(0,10pt) -- cycle;
\foreach \k in {1,...,6}{\draw[white, line width=2pt] (-4pt*\k,-5pt) -- ++(0,10pt);}
}
}
}
}
]
\foreach \i in {0,45,...,315} {\draw[MyArrow=orange] (0,0) -- ++(\i:2);}
\foreach \i in {0,45,...,315} {\draw[MyArrow=blue, rounded corners] (4,0) --++(\i:1) -- ++(45+\i:2);}
\draw[MyArrow=red](0,0) [out=-15,in=180] to ++(4,-3)[out=0,in=180] -- ++(2,0);
\foreach \distance in {0,1,...,40}{
\pgfmathparse{0.9*rnd+0.3}
\definecolor{Rcolor}{rgb}{\pgfmathresult,\pgfmathresult,\pgfmathresult} % from https://tex.stackexchange.com/a/37279/154390
\draw[MyArrow=green!50!Rcolor,brown!50!Rcolor] (-1.7,-6)++(\distance*0.22,0) -- ++(0,2+0.7*rand*rand););
}
\end{tikzpicture}
\end{document}
答案3
有点笨拙。直接画出形状会更容易,但如果你特别想要一个箭头:
\documentclass{standalone}
\usepackage{tikz}
% ateb: https://tex.stackexchange.com/a/702116/
% cwestiwn Medulla Oblongata: https://tex.stackexchange.com/q/702111/
\usetikzlibrary{arrows.meta}
\usetikzlibrary{patterns.meta}
\begin{document}
\begin{tikzpicture}[very thick,font=\sffamily\Large]
\draw[-{Latex[length=30mm,angle'=10]},line width=0pt,postaction={draw,-,shorten >=30mm-1.2pt,black,very thick},white,pattern={Lines[line width=2.5pt,distance=5pt]},pattern color=orange] (0,-2) -- (0,3);
\end{tikzpicture}
\end{document}
如果不必是箭头,您可以简单地填充三角形路径。这不依赖于背景是否为白色。
\documentclass{standalone}
% ateb: https://tex.stackexchange.com/a/702116/
% cwestiwn Medulla Oblongata: https://tex.stackexchange.com/q/702111/
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{patterns.meta}
\begin{document}
\begin{tikzpicture}[very thick,font=\sffamily\Large]
\draw[-{Latex[length=30mm,angle'=10]},line width=0pt,postaction={draw,-,shorten >=30mm-1.2pt,black,very thick},white,pattern={Lines[line width=2.5pt,distance=5pt]},pattern color=orange] (0,-2) -- (0,3);
\begin{scope}[xshift=10mm]
\draw[shorten >=30mm-1.2pt,black,very thick] (0,-2) -- (0,3);
\path [pattern color=orange,pattern={Lines[line width=2.5pt,distance=5pt]}] (-.5,0) -- (0,3) -- (.5,0) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}