0

In Tikz I would like to display multiple overlapping grids such that the last one covers the previous ones. This is the code and the wrong output I get, where you can see the intermediate line of all grids. The fill=white parameter seems to not work.

\begin{tikzpicture}
    \foreach \i in {0, 0.5, ..., 1.5}
        \draw[fill=white, xshift=\i cm, yshift=-\i cm] (0, 0) grid (4, 4);
\end{tikzpicture}

enter image description here

4
  • Which part is wrong in the output?
    – Alenanno
    Commented Nov 30, 2020 at 11:44
  • 1
    Grid is is not a shape, it is composed from lines, so in it is nothing to fill.
    – Zarko
    Commented Nov 30, 2020 at 11:45
  • Is this what you want to achieve?
    – Alenanno
    Commented Nov 30, 2020 at 12:02
  • @Alenanno yes exactly..
    – aretor
    Commented Nov 30, 2020 at 12:29

1 Answer 1

1

It seems that you like to get the following:

enter image description here

Above image is composed from square shapes. One way to do this is:

\documentclass[tikz, margin=3mm]{standalone}

\begin{document}
\begin{tikzpicture}
\foreach \k in {0, 0.5, 1, 1.5}
{
    \begin{scope}[shift={(\k cm,-\k cm)}]
    \foreach \i in {0, 1,...,4}
    {
        \foreach \j in {0,1,...,4}
            \node[draw, fill=white, minimum size=1 cm, outer sep=0pt]
                  at (\i, \j) {};
    }
    \end{scope}
}
\end{tikzpicture}
\end{document}

Addendum: Simpler is to draw grid in rectangles with white fill:

\documentclass[tikz, margin=3mm]{standalone}

\begin{document}
\begin{tikzpicture}
    \foreach \i in {0, 0.5, ..., 1.5}
{
\draw[fill=white, xshift=\i cm, yshift=-\i cm] (0, 0) rectangle (4, 4);
\draw[xshift=\i cm, yshift=-\i cm] (0, 0) grid (4, 4);
}
\end{tikzpicture}
\end{document}

Result is the same as before

3
  • So it cannot be done with grids, but with rectangles only?
    – aretor
    Commented Nov 30, 2020 at 12:31
  • @aretor, not only with grid. See addendum to answer.
    – Zarko
    Commented Nov 30, 2020 at 12:32
  • The second solution is what I was searching for, thanks.
    – aretor
    Commented Nov 30, 2020 at 12:32

You must log in to answer this question.

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