13

Is there an easy way to draw the discontinuity symbol with tikz?

It is the symbol shown at the y axis in the following picture (taken from the pgfplots documentation.

I can always draw it manually but it is not always easy especially if the line has an angle. I tried to do it with a style, but I couldn't figure it out.

Optimally I would like to just specify the start and the end point of a line segment and the sign should be drawn in the center.

my picture

Update

Jake solution is nice, but it doesn't work nicely with filling. Is there a way to draw the symbol while filling continues to work?

Leo Liu's answer works with filling but you have to tweak the parameters each time you use it.

0

3 Answers 3

13

Here's a solution that uses the decorations library and declares a new discontinuity decoration, which is essentially a single zigzag in the middle of the first segment of a path. The length and amplitude of the discontinuity symbol are controlled using the standard decoration options segment length and amplitude.

Discontinuity symbol

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations}

\begin{document}

\pgfdeclaredecoration{discontinuity}{start}{
  \state{start}[width=0.5\pgfdecoratedinputsegmentremainingdistance-0.5\pgfdecorationsegmentlength,next state=up from center]
  {}
  \state{up from center}[width=+.5\pgfdecorationsegmentlength, next state=big down]
  {
    \pgfpathlineto{\pgfpointorigin}
    \pgfpathlineto{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
  }
  \state{big down}[next state=center finish]
  {
    \pgfpathlineto{\pgfqpoint{.25\pgfdecorationsegmentlength}{-\pgfdecorationsegmentamplitude}}
  }
  \state{center finish}[width=0.5\pgfdecoratedinputsegmentremainingdistance, next state=do nothing]{
    \pgfpathlineto{\pgfpointorigin}
    \pgfpathlineto{\pgfpointdecoratedinputsegmentlast}
  }
  \state{do nothing}[width=\pgfdecorationsegmentlength,next state=do nothing]{
    \pgfpathlineto{\pgfpointdecoratedinputsegmentlast}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointdecoratedpathlast}
  }
}

\begin{tikzpicture}
\draw [fill=yellow,decoration={discontinuity,amplitude=1ex},decorate](0,0) -- (3,2)  --  (5,1) -- cycle;
\end{tikzpicture}
\end{document}
1
  • now that I've delved deeper in tikz, I 've started to understand what you did here. It is great! thank you!
    – pmav99
    Commented Jun 9, 2011 at 10:02
17

pgfplots has discontinuities decoration on the axis. See '4.8.11 Axis Discontinuities' in the manual.

Example in the manual:

% \usepackage{pgfplots}
\begin{tikzpicture}
\begin{axis}[
axis x line=bottom,
axis y line=center,
tick align=outside,
axis y discontinuity=crunch,
ymin=95, enlargelimits=false
]
\addplot[blue,mark=none,
domain=-4:4,samples=20]
{x*x+x+104};
\end{axis}
\end{tikzpicture}

enter image description here

It is implemented using zigzag decorations. Then you can draw it your self, for example (it is not a good implementation):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\tikzset{discont/.style={decoration={zigzag,segment length=12pt, amplitude=4pt},decorate}}
\def\discontarrow(#1)(#2)(#3)(#4);{
  \draw[discont] (#2) -- (#3);
  \draw[->] (#1) -- (#2) (#3) -- (#4);
}
\begin{document}
\begin{tikzpicture}
\discontarrow(0,0)(1,0)(1.5,0)(4,0);
\end{tikzpicture}
\end{document}

enter image description here

6
\documentclass{minimal}
\usepackage{pst-coil}
\begin{document}
\begin{pspicture}(4,2)
  \pszigzag[coilarm=1.5cm](0,0)(4,2)
\end{pspicture}
\end{document}

enter image description here

You must log in to answer this question.

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