1

I need to repeat the following figure say 3 times in rows, i.e., below one another preferably using a loop. How can I do that? Thanks!

enter image description here

\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}
2

1 Answer 1

4

You can use a \foreach loop and perform a vertical shift within a scope as follows. Note that you have to move the start chain=going right into the scope for the shift to work properly.

\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}

enter image description here

3
  • Thanks. Is there a way to make lambdas to be denoted \lambda_1, \lambda_2, \lambda_3 using the same counter in the loop? Commented Apr 7, 2017 at 1:13
  • Yes, of course, let me edit this.
    – AboAmmar
    Commented Apr 7, 2017 at 1:20
  • I think I got it! multiplying by 2 in \y and changing the coordinates works. Thanks. Commented Apr 7, 2017 at 1:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .