在tikz中按行重复相同的图形

在tikz中按行重复相同的图形

我需要将下图重复 3 次,即一行接一行,最好使用循环。我该怎么做?谢谢!

在此处输入图片描述

\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{tikz}
\usetikzlibrary{chains,shapes.multipart}
\usetikzlibrary{shapes,calc}
\usetikzlibrary{automata,positioning}
\begin{document} 
   \begin{figure}
   \centering
   \begin{tikzpicture}[start chain=going right,>=latex,node distance=0pt]
    \node[draw,rectangle,on chain,draw=white,minimum size=1.3cm]{};
    \node[rectangle split, rectangle split parts=6,
    draw, rectangle split horizontal,text height=0.5cm,text depth=0.5cm,on chain,inner ysep=0pt] (wa) {};
    \fill[white] ([xshift=-\pgflinewidth,yshift=-\pgflinewidth]wa.north west) rectangle ([xshift=-15pt,yshift=\pgflinewidth]wa.south);
    \node at (wa.east) (A){};
    \draw [-latex] (A) --+(0:1) coordinate (B1);
    \node [draw,circle,on chain,minimum size=1cm] at (B1) (se1) {$n$};
    \draw[<-] (wa.west) --+(-20pt,0) node[left] {$\lambda_1$};
   \end{tikzpicture}
   \end{figure}
\end{document}

答案1

您可以使用\foreach循环并在 内执行垂直移位,scope如下所示。请注意,您必须将 移入start chain=going right范围内,移位才能正常工作。

\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{tikz}
\usetikzlibrary{chains,shapes.multipart}
\usetikzlibrary{shapes,calc}
\usetikzlibrary{automata,positioning}
\begin{document} 
   \begin{figure}
   \centering
   \begin{tikzpicture}[>=latex,node distance=0pt]
   \foreach \y [count=\n]in {0,2,4}{ 
   \begin{scope}[yshift = \y cm,start chain=going right]
    \node[draw,rectangle,on chain,draw=white,minimum size=1.3cm]{};
    \node[rectangle split, rectangle split parts=6,
    draw, rectangle split horizontal,text height=0.5cm,text depth=0.5cm,on chain,inner ysep=0pt] (wa) {};
    \fill[white] ([xshift=-\pgflinewidth,yshift=-\pgflinewidth]wa.north west) rectangle ([xshift=-15pt,yshift=\pgflinewidth]wa.south);
    \node at (wa.east) (A){};
    \draw [-latex] (A) --+(0:1) coordinate (B1);
    \node [draw,circle,on chain,minimum size=1cm] at (B1) (se1) {$n$};
    \draw[<-] (wa.west) --+(-20pt,0) node[left] {$\lambda_\n$};
    \end{scope}
    }
   \end{tikzpicture}
   \end{figure}
\end{document}

在此处输入图片描述

相关内容