Tikz 蛇箭

Tikz 蛇箭

根据手册的建议,我使用以下代码绘制蛇形线。我定义了一个snake arrow/.style,当我将它应用于单个 ' 时,它工作得很好。但如果我将它应用于分组或 ,edge它就不起作用。\draw\path

\documentclass[a4paper,12pt]{amsart}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,decorations.pathmorphing}
\tikzset{snake arrow/.style=
{->,
decorate,
decoration={snake,amplitude=.4mm,segment length=2mm,post length=1mm}}
}
\begin{document}

\begin{tikzpicture}
  \foreach \i in {0,...,4}{
  \node (p\i) at (2\i, 4\i+1){}; % random node
  }
  \draw%[snake arrow] %this does not work
  (p0) edge[snake arrow] (p1)% this works
  (p2) edge (p4);
\end{tikzpicture}

\end{document}

答案1

您提供的选项\draw将仅应用于第一段。您可以将所有蛇形边缘分组到范围内,然后放入

every edge/.style={draw,snake arrow} 

作为范围的选项以使其成为本地。

\documentclass[a4paper,12pt]{amsart}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,decorations.pathmorphing}
\tikzset{snake arrow/.style=
{->,
decorate,
decoration={snake,amplitude=.4mm,segment length=2mm,post length=1mm}},
}
\begin{document}

\begin{tikzpicture}
\begin{scope}[every edge/.append style = {snake arrow}]
  \foreach \i in {0,...,4}{
  \node (p\i) at (2\i, 4\i+1){}; % random node
  }
  \draw %this does not work
  (p0) edge (p1)% this works
  (p2) edge (p4);
\end{scope}
\begin{scope}[xshift=2cm]
  \foreach \i in {0,...,4}{
  \node (p\i) at (2\i, 4\i+1){}; % random node
  }
  \draw %this does not work
  (p0) edge (p1)% this works
  (p2) edge (p4);
\end{scope}  
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容