在这种情况下,我需要通过标记箭头(右侧)连接矩形:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{arrows, chains}
\begin{document}
\begin{tikzpicture}[
node distance = 0mm,
start chain = going right,
box/.style = {draw, semithick, minimum size=1cm,
outer sep = 3mm, on chain,}
]
\foreach \i in {{\Huge S_0}, S_1, S_2, S_3, S_4, S_5, S_6, S_7, S_8}
\node[box,label=below:] {$\i$};
\end{tikzpicture}
\end{document}
我还需要用 n 来标记箭头,\lambda_n
其中 n 是从 0 到 7 的数字。标签应放在箭头上方。
答案1
没有的话chains
,只有两个简单的\foreach
循环:
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}[box/.style = {draw, semithick, minimum size=1cm}]
\foreach \n in {0,...,8}
\node at (1.7*\n, 0) [box] (\n) {$S_\n$};
\foreach \n [count=\i] in {0,...,7}
\draw[-{latex}] (\n) -- node[above] {$\lambda_\n$} (\i);
\end{tikzpicture}
\end{document}
答案2
添加箭头作为进一步的节点on chain
。
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{arrows, chains}
\begin{document}
\begin{tikzpicture}%
[node distance = 0mm,
start chain = going right,
box/.style = {draw, semithick, minimum size=1cm, on chain}
]
\foreach \i in {0,...,7}
{\node[box,label=below:] {$S_\i$};
\node[on chain] {$\stackrel{\lambda_\i}\longrightarrow$};
}
\node[box,label=below:] {$S_8$};
\end{tikzpicture}
\end{document}
答案3
没有链条,只有一个环
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}%
[
box/.style = {draw, semithick, minimum size=1cm}
]
\node[box] (box0) {$S_0$};
\foreach \i [remember=\i as \lasti (initially 0)] in {1,...,8}
\draw[-{Latex}] (box\lasti) --
node[above]{$\lambda_\lasti$} ++(1.2,0)
node[box, anchor=west] (box\i) {$S_\i$};
\end{tikzpicture}
\end{document}