1

This question already has an answer here:

documentclass[border={5mm}]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=1,
    default rectangle/.style={rectangle, draw=black,thin, minimum size=1cm},    
    ]
%----------------------------------------------------------------------------
% fuel Assembly
%----------------------------------------------------------------------------
% Water around the assembly

 \foreach \x in {-10,-5}{
    \foreach \y in {-1,4}{
      \draw[black,very thin, fill=blue!50!white] (\x,\y) rectangle (-10,4);

% side plate left

       \foreach \x in {-9.9,-9.4}{
         \foreach \y in {-0.9,3.9}{      
           \draw[black,very thin, fill=gray!20!white] (\x,\y) rectangle (-9.4,3.9);

% side plate right

           \foreach \x in {-5.6,-5.1}{
            \foreach \y in {-0.9,3.9}{      
              \draw[black,very thin, fill=gray!20!white] (\x,\y) rectangle (-5.1,3.9);

% 19 fuel plates 

               \foreach \position in {(-5.6,-0.8)}{
                 \draw[black,very thin, fill=gray!50!white] \position rectangle (-9.4,-0.7);


                  }
                }
              }
             }
           }
         }
       }

 \end{tikzpicture}

\end{document}

I am trying to reproduce the picture of a fuel assembly below. My problem is to repeat the 19 plates of the assembly using the loops, i.e. \foreach. Is there a way to avoid repeating the use of \foreach loop for all the 19 plates? Basically I need to build the plate once and just repeat it 19 times as in the attached picture. Thanking you in advance for your assistance. enter image description here

marked as duplicate by cfr tikz-pgf Jan 10 '16 at 2:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Didn't this previous question solve this problem? cfr's answer there has only two foreach loops. – Alenanno Jan 9 '16 at 10:43
  • @Alenanno It is a different user? But the same question? – cfr Jan 10 '16 at 2:04
  • Is this a question in someone's homework or something? Seems weird to get 2 questions asking to draw just this so close together.... I guess the colours are slightly different in this one. – cfr Jan 10 '16 at 2:05
4

Tikz includes the calc package by default. That means you can use normal operations like + and -. To draw the included picture I would use something like this.

\documentclass[border={5mm}]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=1,
  default rectangle/.style={rectangle, draw=black,thin, minimum size=1cm}]
  % ----------------------------------------------------------------------------
  % fuel Assembly
  % ----------------------------------------------------------------------------
  % Water around the assembly
  \def\numRep{19}
  \def\Marg{0.1}
  \draw[blue,fill=blue](0-\Marg,0-\Marg) rectangle (15+\Marg,\numRep+\Marg);
  \foreach \Y in {1,2,...,\numRep}{
    \draw[blue,fill=green] (0,\Y-1) rectangle (15,\Y);
    \draw[blue,fill=blue] (1,\Y-1) rectangle (14,\Y-0.65);
    \draw[blue,fill=blue] (1,\Y-0.35) rectangle (14,\Y);
    \draw[blue,fill=red] (1.5,\Y-0.55) rectangle (13.5,\Y-0.45);
    %% Lines horisontal
    \foreach \Yline in {0.35,0.45,0.55,0.65} \draw[blue] (1,\Y-\Yline) -- +(13,0);
  };
  %% Lines vertical
  \foreach \Xline in {0,1,...,6} \draw[blue] (2*\Xline+1.5,0) -- +(0,\numRep);
  \draw[blue] (1,0) -- +(0,\numRep);
  \draw[blue] (14,0) -- +(0,\numRep);
\end{tikzpicture}
\end{document}
  • Nice solution! What is purposes of code line default rectangle/.style={rectangle, draw=black,thin, minimum size=1cm}? It seems that it is surplus. – Zarko Jan 9 '16 at 12:27
  • @Zarko, yes you are right. The optional parameters for tikzpicture is a copy-paste from the question and can be removed. scale=1 is default and the other is not used. – StefanH Jan 10 '16 at 9:24

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