装饰与元箭头重叠

装饰与元箭头重叠

当使用带有开放元箭头的装饰时,装饰似乎会穿过箭头。有什么方法可以防止这种情况发生吗?

在此处输入图片描述

(我知道调整post length是可行的,但我希望当箭头尖端、其大小或线宽改变时不需要进行调整)

\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

我曾有一个类似问题次以前。

利用华丽的答案通过符号 1,我认为也可以解决您的问题。

我创建了一个有两个选项的样式:箭头类型和长度,分别使用默认值Stealth10pt。当然,它可以进一步定制。

\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}

在此处输入图片描述

相关内容