2

I have a problem regarding making a lots of grid i tikz.

my code is as follows:

 \begin{tikzpicture}
 \path[use as bounding box,draw] (12,18) rectangle (0,0);

 \foreach \x in {0,2,4,8}
 \draw[black] (0.999+\x,17) grid[step=0.2] (2+\x,15.999);

 \draw[->] (3.5,15.5) -- (3.5,13);
 \draw[->] (9.5,15.5) -- (9.5,13);

 \foreach \x in {2,4,6,8}
 \draw[black] (0.999+\x,12) grid[step=0.2] (2+\x,10.999);

  \draw[->] (6.5,10) -- (6.5,9);

  \draw[black] (5.999,8.100) grid[step=0.2] (7,7.099) node {};
  \end{tikzpicture}

enter image description here

One can clearly see that the grid in the third row are not drawn corretly.

Hope that any of your can help.

  • 1
    Welcome to TeX.SX! Please make your code compilable by adding documentclass and required packages. – TeXnician Jul 17 '17 at 15:08
  • I guess that instead of \draw[black] (5.999,8.100) grid[step=0.2] (7,7.099) node {}; should be \draw[black] (5.999,8.100) grid[step=0.2] (7,6.99) node {}; – Zarko Jul 17 '17 at 15:17
  • What's the point of the node {}? – cfr Jul 17 '17 at 15:18
2

If you define your grid as small picture pic than you can rewrite your MWE as:

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

\begin{document}
\begin{tikzpicture}[
   GRID/.pic={\draw (0,0) grid[step=0.2] (1,1);}
                    ]
\path[use as bounding box,draw] (12,18) rectangle (0,0);

\foreach \x in {1,3,5,9}
\pic at (\x,16) {GRID};
\draw[->] (3.5,15.5) -- (3.5,13);
\draw[->] (9.5,15.5) -- (9.5,13);
%\fill[red] (1,16) circle (1mm);% for test of pic coordinate

\foreach \x in {3,5,7,9}
\pic at (\x,11.5) {GRID};
\draw[->] (6.5,11) -- (6.5,9);

\pic at (6,7.5)  {GRID};
  \end{tikzpicture}
\end{document}

enter image description here

(image not contain bounding box).

4

Grids are shifted so that they always meet at the current origin. The trick is to shift the origin with the shift key:

\documentclass[tikz,border=5]{standalone}
\begin{document}
\begin{tikzpicture}
\draw [red] (0,0) grid +(4,4);
\draw [green, dashed] (0.5,0.5) grid +(4,4);
\draw [blue, dotted, shift={(0.5,0.5)}] (0,0) grid +(4,4);
\end{tikzpicture}
\end{document}

enter image description here

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.