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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.