TikZ 中箭头缩短的问题

TikZ 中箭头缩短的问题

我对箭头提示有问题。我想画一个像这张图片中水平箭头那样的箭头(这只是一个 MWE):

图像

箭头尖端的位置是正确的(左侧的圆圈必须位于 NO-SO 垂直线上方,右侧的尖端必须在 NE-SE 垂直线前几个点结束)。问题是,如果我使用波浪shorten线,会很乱。我该如何修复它?

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

附加问题:当 E 和 O 节点按照我的代码定义时,有没有办法水平移动它们,而无需定义辅助节点?

谢谢你!

答案1

您的装饰的解决方案是添加pre length=4ptpost 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}

对于您的奖励问题,您只需添加xshift=-4pt到节点选项,但这仍然需要一些post- 和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}

在这两种情况下,结果看起来(或多或少)像这样:

在此处输入图片描述

相关内容