8

I have a problem with arrow tips. I want to draw an arrow like the horizontal one in this image (this is just a MWE):

image

The position of the arrow tips is correct (the circle on the left must be over the NO-SO vertical line, and the tip on the right must end a few pt before the NE-SE vertical line). The problem is that if I use shorten the wawy line is a mess. How can I fix it?

\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
  \node (NO) at (-2,+1.5) {NO};
  \node (SO) at (-2,-1.5) {SO};
  \node (NE) at (+2,+1.5) {NE};
  \node (SE) at (+2,-1.5) {SE};
  \draw [<->] (NO) -- node[coordinate] (O){} (SO);
  \draw [<->] (NE) -- node[coordinate] (E){} (SE);
  \draw [
      {Circle[width=8pt, length=8pt, open]}-{Triangle[scale=1.5]},
      decorate, decoration=snake, thick, shorten <=-4pt, shorten >= 4pt
    ] (O) -- (E);
\end{tikzpicture}
\end{document}

Bonus question: is there any way to shift horizontally the E and O nodes when they are defined as in my code, without defining auxiliary nodes?

Thank you!

  • Regarding the bonus question, do you mean that you want to change where the arrow hits the node? – Torbjørn T. Jul 3 '18 at 16:23
  • I mean that I want to change the node position instead of using shorten, but this would be just a workaround (I'd prefer to use shorten and fix the line isdue). Also, I need that for another picture – Taekwondavide Jul 3 '18 at 16:34
  • 3
    Sorry, I actually looked at the wrong nodes. Use for example coordinate[right=10pt] (O) to move O 10pt to the right. – Torbjørn T. Jul 3 '18 at 16:36
  • How do I use that? Is it an option for node or does it replace node? – Taekwondavide Jul 4 '18 at 14:47
  • 1
    coordinate is short for node[coordinate], so coordinate[...] (O) replaces node[coordinate, ...] (O){}. – Torbjørn T. Jul 4 '18 at 14:55
11

The solution for your decoration is to add pre length=4pt and post length=9pt.

\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
  \node (NO) at (-2,+1.5) {NO};
  \node (SO) at (-2,-1.5) {SO};
  \node (NE) at (+2,+1.5) {NE};
  \node (SE) at (+2,-1.5) {SE};
  \draw [<->] (NO) -- node[coordinate] (O){} (SO);
  \draw [<->] (NE) -- node[coordinate] (E){} (SE);
  \draw [
      {Circle[width=8pt, length=8pt, open]}-{Triangle[scale=1.5]},
      decorate, decoration={snake,pre length=4pt,post length=9pt}, thick, shorten <=-4pt, shorten >= 4pt
    ] (O) -- (E);
\end{tikzpicture}
\end{document}

For your bonus question, you could just add xshift=-4pt to the node options, but this still needs some post- and pre length.

\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
  \node (NO) at (-2,+1.5) {NO};
  \node (SO) at (-2,-1.5) {SO};
  \node (NE) at (+2,+1.5) {NE};
  \node (SE) at (+2,-1.5) {SE};
  \draw [<->] (NO) -- node[coordinate,xshift=-4pt] (O){} (SO);
  \draw [<->] (NE) -- node[coordinate,xshift=-4pt] (E){} (SE);
  \draw [
      {Circle[width=8pt, length=8pt, open]}-{Triangle[scale=1.5]},
      decorate, decoration={snake,pre length=8pt,post length=8pt}, thick] (O) -- (E);
\end{tikzpicture}
\end{document}

In both cases the result looks (more or less) like this:

enter image description here

  • Thank you! How did you get the post length value? By trials or did you calculate it somehow? – Taekwondavide Jul 4 '18 at 14:34
  • @Taekwondavide ashamed I admit by trial and error :) – Max Jul 4 '18 at 14:55

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.