TikZ: Decoration with 1cm zigzag in the middle of a link

How do I make a TikZ decoration with a 1cm zigzag in the middle?

Here's what I have so far, but it didn't work:

\pgfdeclaremetadecoration{timearrow}{initial}{
\state{initial}[width=0pt, next state=arrow] {
\pgfsetlinewidth{1pt}
\pgfset{/pgf/decoration/segment length=8pt}
}
\state{arrow}[switch if less than=1cm to final,
width=\blah ,
next state=zigzag] {
\decoration{curveto}
}
\state{zigzag}[width=1cm,
next state=final] {
\decoration{zigzag}
}
\state{final}[] {
\decoration{curveto}
}
}

-
Have a look at Draw the discontinuity symbol with tikz. – Martin Scharrer Oct 30 '11 at 22:34

Your style worked for me, except for the fact that the zigzag segment wasn't centred correctly because you shifted it by 1cm, not by 0.5cm.

I would suggest to keep as many of the lengths in your decoration as variables, instead of hard coding your values. If you set \pgfset{/pgf/decoration/segment length=8pt}, you rob yourself of the freedom to change the zigzag wavelength by setting segment length=<value> as an option to your decoration. The same goes for \pgfsetlinewidth{1pt}: If you leave out this line, you can just specify the line width as you would with any other TikZ path. If you need to draw the decoration frequently with the same values, you can just define a new style that sets these for you.

Also, you don't need to say \beforedecoration{\pgfpathmoveto{\pgfpointmetadecoratedpathfirst}} at the beginning of each segment if your segments are joined.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations,decorations.pathmorphing}

\state{straight}[switch if less than=\pgfmetadecorationsegmentlength to final,
next state=zigzag] {
\decoration{curveto}
}
next state=final] {
\decoration{zigzag}
}
\state{final}{
\decoration{curveto}
}
}

\tikzset{
middle zigzag/.style={
decorate,
decoration={
middlezigzag,
meta-segment length=#1,
segment length=0.5cm
}
},
middle zigzag/.default=1cm
}

\begin{document}
\begin{tikzpicture}
\draw [gray!50,yshift=-0.5cm] (0,0) grid (5,1);
\draw [middle zigzag, ultra thick] (0,0) -- (5,0);
\end{tikzpicture}
\end{document}

-
Wow! Thanks! I was just going to adapt the solution at Martin's link, but I'm glad that I was too busy today to do this as I really appreciate all of the tips you included with your solution. – Neil G Oct 31 '11 at 6:48