绘制一条间距相同的“箭头线”

绘制一条间距相同的“箭头线”

我有一个矩形节点,想要绘制多个朝一个方向的箭头,并且彼此之间有固定的距离。

我当前的 MWE 的缺点是 foreach 语句中写入的距离是手动尝试和错误,因为两个值之间的相等距离​​不会导致箭头之间的距离相等:

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node[rectangle, draw](down){this is a very long test node};
\node[rectangle, draw, above of = down](up){this is a very long test node};
\foreach \x in {165,150, 90, 30, 15}
{\draw (down.\x) to ++ (0,.4);
}
\end{tikzpicture}
\end{document}

图片如下[这是想要的]:

在此处输入图片描述

使用更自动生成的方式,例如说这种模式:

\foreach \x in {160, 150, 140, 130, 120, 110, 100, 90}
{\draw (down.\x) to ++ (0,.4);} 

这导致了这个[不想要]:

在此处输入图片描述

有没有更好的方法来创建从一个节点向一个方向的箭头,或者使用节点的位置标记(160、155、...)'更好',而不仅仅是尝试和错误?

答案1

众多可能性中的一种。calc 库带来了更多奇特的可能性。

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node[rectangle, draw](down){this is a very long test node};
\node[rectangle, draw, above of = down](up){this is a very long test node};
\foreach \x [count=\y] in {0.1,0.3,0.5,0.7,0.9}
{\path (down.north west) -- (down.north east) coordinate[pos=\x] (p\y);
\draw (p\y) to (up.south -| p\y);
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

类似marmot's解决方案,但带有calc库:

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning, calc}
\begin{document}
\begin{tikzpicture}
\node[rectangle, draw](down){this is a very long test node};
\node[rectangle, draw, above of = down](up){this is a very long test node};
\foreach \x in {0.1,0.3,0.5,0.7,0.9}
\draw ($(up.south west)!\x!(up.south east)$) coordinate (aux) -- (aux|-down.north);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容