10

I want to draw a shortened squiggly arrow, like the following:

short squiggly arrow

However, when I use shorten in combination with squiggly, I get a strange effect, where the shortened segment is drawn both as squiggly and as a straight line (rather than not drawn at all):

bad squiggly arrow

The code is:

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
\begin{tikzcd}
    \bullet && \bullet
    \arrow[shorten <=10pt, shorten >=10pt, squiggly, from=1-1, to=1-3]
\end{tikzcd}
\end{document}

Is there a way to work around this issue?

0

2 Answers 2

9

You'll need to shorten the decoration itself in addition to the path. Found an old reference to this in http://pgf-and-tikz.10981.n7.nabble.com/shorten-and-decoration-td2248.html, and seems it still applies. Hence, you need to say squiggly={pre length=10pt, post length=10pt} in addition to the shortens.

output of code with shortened arrow

\documentclass[border-5mm]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
\begin{tikzcd}
    \bullet && \bullet
    \arrow[shorten <=10pt, shorten >=10pt,
            squiggly={
               pre length=10pt, post length=10pt
             },
             from=1-1, to=1-3]
\end{tikzcd}
\end{document}
4
  • The amplitude/contraction of your squiggly is different of the first image. Is it possible to change?+1 for you excellent work.
    – Sebastiano
    Jun 6, 2021 at 20:25
  • 2
    @Sebastiano The code I added didn't change anything about the amplitude and wavelength. But yes, you can change those things if you want to, add e.g. segment length=2mm, amplitude=2mm in the argument to squiggly, along with pre length and post length. Jun 6, 2021 at 20:32
  • Thank you very much for the addition of explanation.
    – Sebastiano
    Jun 6, 2021 at 20:34
  • Perfect, thanks!
    – varkor
    Jun 7, 2021 at 11:07
9

Another possibility could be replace the shortens by start anchor and end anchor

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
\begin{tikzcd}
    \bullet && \bullet
    \arrow[squiggly, start anchor={[xshift=10pt]}, end anchor={[xshift=-10pt]}, from=1-1, to=1-3]
\end{tikzcd}
\end{document}

enter image description here

3
  • Very very good. +1 for your code.
    – Sebastiano
    Jun 6, 2021 at 20:35
  • 1
    Thanks, although it would be nice not to have to change shorten key as in Torbjørn T answer Jun 6, 2021 at 20:40
  • Thanks, this is a simple solution for vertical or horizontal arrows, though becomes a little trickier with diagonals where the offset has to be calculated manually.
    – varkor
    Jun 7, 2021 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.