我怎样才能画一列矩形火车?

我怎样才能画一列矩形火车?

如何用 TikZ 绘制矩形火车?在此处输入图片描述

答案1

你可以使用这样的链条

编辑Torbjørn T. 的评论更加优雅。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{chains,shapes}% both are needed for the original code in the question

\begin{document}

\begin{tikzpicture}[start chain,>=latex,node distance=0.7cm]
  { [start chain=trunk going right]

     \node[draw,rectangle,on chain,minimum size=1cm] (rect1) {$G_1$};
     \node[draw,rectangle,on chain,minimum size=1cm] (rect2) {$G_2$};
     \node[draw,rectangle,on chain,minimum size=1cm] (rect3) {$G_3$};
     \node[draw,rectangle,on chain,minimum size=1cm] (rect4) {$G_4$};
     \node[draw,rectangle,on chain,minimum size=1cm] (rect5) {$G_5$};
  }

% the arrows and labels
\draw (rect1) -- (rect2) node[midway,above] {$k_1$};
\draw (rect2) -- (rect3) node[midway,above] {$k_2$};
\draw (rect3) -- (rect4) node[midway,above] {$k_3$};
\draw (rect4) -- (rect5) node[midway,above] {$k_4$};

\end{tikzpicture}

\end{document}

并且你获得在此处输入图片描述

相关内容