谢谢这个答案,这是我的代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{math}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.pathreplacing}
\tikzset{%
rev/.style={
postaction={%
decoration={
show path construction,
lineto code={
\tikzmath{
coordinate \I, \F, \v;
\I = (\tikzinputsegmentfirst);
\F = (\tikzinputsegmentlast);
\v = ($(\I) -(\F)$);
real \d, \a, \r, \t;
\d = 0.8;
\t = atan2(\vy, \vx);
if \vx<0 then { \a = 90; } else { \a = -90; };
{
\draw[arrows={-latex}, decorate,
decoration={%
snake, amplitude=.4mm,
segment length=2mm,
post length=1mm
}]
($(\F)!.5!(\I) +(\t: -\d em) +(\t +\a: 1ex)$)
-- ++(\t: 2*\d em);
};
}
}
},
decorate
}
}
}
\begin{document}
\begin{tikzpicture}[->,thick,every node/.style={draw,circle}]
\node (v) {v};
\node [below left=1cm of v] (a) {a};
\node [below right=2cm of v] (b) {b};
\draw (v) edge[bend right=10,rev] (a);
\draw (v) edge[rev] (b);
\end{tikzpicture}
\end{document}
其渲染效果如下:
如您所见,当bend right
存在时,蛇形箭头不会被渲染。为什么以及如何修复?
答案1
弯曲线不是 lineto 操作而是 curveto 操作,因此您也需要执行此操作的代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{math}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.pathreplacing}
\tikzset{%
rev/.style={
postaction={%
decoration={
show path construction,
curveto code={
\tikzmath{
coordinate \I, \F, \v;
\I = (\tikzinputsegmentfirst);
\F = (\tikzinputsegmentlast);
\v = ($(\I) -(\F)$);
real \d, \a, \r, \t;
\d = 0.8;
\t = atan2(\vy, \vx);
if \vx<0 then { \a = 90; } else { \a = -90; };
{
\draw[arrows={-latex}, decorate,
decoration={%
snake, amplitude=.4mm,
segment length=2mm,
post length=1mm
}]
($(\F)!.5!(\I) +(\t: -\d em) +(\t +\a: 1ex)$)
-- ++(\t: 2*\d em);
};
}
},
lineto code={
\tikzmath{
coordinate \I, \F, \v;
\I = (\tikzinputsegmentfirst);
\F = (\tikzinputsegmentlast);
\v = ($(\I) -(\F)$);
real \d, \a, \r, \t;
\d = 0.8;
\t = atan2(\vy, \vx);
if \vx<0 then { \a = 90; } else { \a = -90; };
{
\draw[arrows={-latex}, decorate,
decoration={%
snake, amplitude=.4mm,
segment length=2mm,
post length=1mm
}]
($(\F)!.5!(\I) +(\t: -\d em) +(\t +\a: 1ex)$)
-- ++(\t: 2*\d em);
};
}
}
},
decorate
}
}
}
\begin{document}
\begin{tikzpicture}[->,thick,every node/.style={draw,circle}]
\node (v) {v};
\node [below left=1cm of v] (a) {a};
\node [below right=2cm of v] (b) {b};
\draw (v) edge[bend right=10,rev] (a);
\draw (v) edge[rev] (b);
\end{tikzpicture}
\end{document}