![绘制多个箭头作为公交车](https://linux22.com/image/257102/%E7%BB%98%E5%88%B6%E5%A4%9A%E4%B8%AA%E7%AE%AD%E5%A4%B4%E4%BD%9C%E4%B8%BA%E5%85%AC%E4%BA%A4%E8%BD%A6.png)
这是我的第一篇文章,我已经使用 LaTeX 有一段时间了,但坦率地说,我还是个新手。
但这个问题更多的是关于 TikZ 而不是 LaTeX:
我想画类似这样的东西,一组平行箭头来表示数字系统中的总线,有人知道该怎么做吗?
答案1
呼呼!
结果:
代码如下:
\documentclass [tikz] {standalone}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{calc}
\newcounter{mynodes}
% node, begin anchor, end anchor, name
\newcommand{\makepoints}[4]{
\foreach \k in {1, ..., \points}
{
\pgfmathsetmacro{\dist}{\k * (1 / (\points + 1))}
\coordinate (#1 #4 \k) at ($(#1.#2)!\dist!(#1.#3)$);
}
}
\begin{document}
\begin{tikzpicture}
% number of arrows between nodes
\pgfmathtruncatemacro{\points}{5}
% square 1
\node [draw, minimum size = 2cm] (square 1) {};
\makepoints{square 1}{south west}{south east}{bottom}
% square 2
\node [draw, minimum size = 2cm] (square 2) at (0, -4cm) {};
\makepoints{square 2}{north west}{north east}{top}
% arrows
\foreach \i in {1, ..., \points} {
\draw [->] (square 1 bottom \i) -- (square 2 top \i);
}
\end{tikzpicture}
\end{document}