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}
5
  • You can change the edge path to a to path. Then it works.
    – Herr K.
    Nov 15, 2013 at 1:51
  • @KevinC I expect two snake arrows, but the to result is two snakes with only one arrow.
    – Ma Ming
    Nov 15, 2013 at 1:53
  • Or, add the [snake arrow] option to both of the edges.
    – Herr K.
    Nov 15, 2013 at 2:02
  • @HarishKumar That is the point I intended to ask. If I have a great deal of snake arrows to draw, I would like to have a grouped solution.
    – Ma Ming
    Nov 15, 2013 at 2:05
  • How about this: put \tikzset{every edge/.style={draw,snake arrow}} somewhere in the TikZ picture, and just use the edge operation as usual?
    – Herr K.
    Nov 15, 2013 at 2:17

1 Answer 1

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

4
  • Hah, you beat me on this one :)
    – Herr K.
    Nov 15, 2013 at 2: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, 2013 at 2:27
  • @KevinC hehe. I was writing my answer first ;-)
    – user11232
    Nov 15, 2013 at 5: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.
    – user11232
    Nov 15, 2013 at 5:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .