3

When using decorations with open meta arrows, the decorations seem to go through the arrow. Is there some way to prevent this?

enter image description here

(I know that adjusting post length would work, but I would like something that does not need to be adjusted when the arrow tip, its size or the line width change)

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\draw[decorate, decoration={zigzag, segment length=2pt, amplitude=1pt, post=lineto, post length=1pt}, -{Stealth[length=10pt, open]}] (0,0) -- (50pt, 0);
\end{tikzpicture}
\end{document}
1
  • A simple trick is to add this: shorten >=-6pt
    – polyn
    Commented Aug 26, 2021 at 9:49

1 Answer 1

4

I had a similar problem times ago.

Taking advantage of the gorgeous answer by Symbol 1, I think it's possible to solve your problem, too.

I created a style with two options: arrow type and length, with the default values Stealth and 10pt, respectively. Of course, it could be further customized.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calc}
% Code from: https://tex.stackexchange.com/a/623891/101651
\makeatletter
\def\computevisuallength#1#2#3{% visual end, visual tip, dummy
    \pgf@x#1
    \pgf@y#2
    \advance\pgf@x-\pgf@y
    \xdef\visuallength{\the\pgf@x}
}
\tikzset{
  mystyle/.style 2 args={%
    decoration={%
      show path construction,
      lineto code={%
        \coordinate (start) at (\tikzinputsegmentfirst);
        \coordinate (end) at (\tikzinputsegmentlast);
        \draw[dash pattern=on0off9999,-{#1[open, length=#2]}] (start) -- (end);
        {
            \pgfsetarrowsend{#1[open, length=#2]}% force pgf recall this arrow
            \def\pgf@arrow@hull@point{hull}%%
            \expandafter\expandafter\expandafter\computevisuallength
            \csname pgf@ar@visual@\pgf@arrow@id\endcsname
        }
        \coordinate (arrowstart) at ($(end)!\visuallength!(start)$);
        \draw[decorate, decoration={zigzag, segment length=2pt, amplitude=1pt, post=lineto, post length=1pt}] (start) -- (arrowstart);
        }
      },
    decorate
  },
  mystyle/.default={Stealth}{10pt},
}

\begin{document}
\begin{tikzpicture}
\draw[mystyle={Latex}{5pt}] (0,2) -- (50pt,1.5);
\draw[mystyle={Triangle}{20pt}] (0,0.5) -- (50pt,1);
\draw[mystyle] (0,0) -- (50pt,0);
\end{tikzpicture}
\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 .