4

As suggested by the manual, I use the following code the draw snake lines. I defined a snake arrow/.style, it works perfect when I apply it to a single edge'. But it does not work if I apply it to a grouped \draw or \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}
Ma Ming
  • 2,306

1 Answers1

5

The options you present to \draw will be applied to the first segment alone. You can group all your snake edges in to a scope and put

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

as the option to the scope to make it local.

\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}

enter image description here

  • Hah, you beat me on this one :) – Herr K. Nov 15 '13 at 02:22
  • So there are two solutions provided, every edge/.append style={snake arrow} or every edge/.style={draw, snake arrow}. It seems work fine, thanks you guys. – Ma Ming Nov 15 '13 at 02:27
  • @KevinC hehe. I was writing my answer first ;-) –  Nov 15 '13 at 05:51
  • 1
    @MaMing every edge/.append style={snake arrow} is better as it will append the style. Hence if you define any special thing previously, it won't be discarded. every edge/.style={draw, snake arrow} will over write previous settings. –  Nov 15 '13 at 05:52