Suppose I need to draw a Kantor set, or a Sierpinski carpet, or a Koch curve, or any such of simple fractal.

Tipically you can do that by drawing a picture, then rescalining it and replicating in several places.

I tried by using \foreach \a in {...} combined to \begin{scope}[shift{some function of \a},scale{some function of \a}]

but I did not succeed.

So which is the correct way to combine a cycle for with moving and rescaling a picture?

More precisely I tried:

\foreach \a in {0,1,2}

\begin{scope}[shift={(10\a,0)}, scale=1/3]


this gives errors

"Extra }, or forgotten \endgroup."

and with group parenthesis

\foreach \a in {0,1,2}

{\begin{scope}[shift={(10\a,0)}, scale=1/3]


which seems just not working.


1 Answer 1


There are two errors in you code.

  1. You probably want to multiply \a by 10, so you have to write 10*\a.
  2. The body of the foreach loop has to be in a brace group if it is more than a single statement. While

    \foreach \a in {0,1,2}
      \node at (10*\a,0) {\a};

    is okay (single statement, ending with ;), this is not

    \foreach \a in {0,1,2}
        \node at (0,0) {\a}; % scanning actually stops at this ;
      \end{scope} % this is not reached -> error!

If you correct these errors, the following MWE typesets just fine.


  \foreach \a in {0,1,2} {
      \node at (0,0) {\a};


You must log in to answer this question.

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