5

Please see what I have written,when I need individual grid on each of picture inside my figure-array. In contrast to previews question Drawing a grid on array of images. Question now is why I can't use \subfloat before \includegraphics in this case? I want to since I need caption below each image. Also I guess it should be some solution to optimize this code, like to define new command and not write grid code on each element of array, since I have more arrays in original document.

\documentclass{article}
\usepackage{subfig}
\usepackage[demo]{graphicx}
\usepackage{tikz}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0){\includegraphics[trim = 10mm 10mm 70mm 20mm,clip,scale=0.15]{image1}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
    \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0){\includegraphics[trim = 10mm 10mm 70mm 20mm,clip,scale=0.15]{image2}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
    \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\end{scope}
\end{tikzpicture}\\
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0){\includegraphics[trim = 10mm 10mm 70mm 20mm,clip,scale=0.15]{image3}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
    \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0){\includegraphics[trim = 10mm 10mm 70mm 20mm,clip,scale=0.15]{image4}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
    \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\end{scope}
\end{tikzpicture}

\caption{Time evolution}
\end{figure}

\end{document}
Moriambar
  • 11,466
Davit
  • 95

1 Answers1

5

A variation of the code used in the answer to the other question; the argument for \mygrid is the object that will receive the grid (in this case, the standard \includegraphics command for inclusion of the image):

\documentclass{article}
\usepackage{subfig}
\usepackage[demo]{graphicx}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}

\newcommand\mygrid[1]{%
\begin{tikzpicture}
  \node[anchor=south west,inner sep=0] (A) 
    {#1};
  \begin{scope}[x={(A.south east)},y={(A.north west)}]
  \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
  \foreach \x in {0,1,...,10} { \node [anchor=north,font=\tiny,inner sep=0pt] at (\x/10,0) {\x}; }
  \foreach \y in {0,1,...,10} { \node [anchor=east,font=\tiny,inner sep=0pt] at (0,\y/10) {\y}; }
  \end{scope}%
\end{tikzpicture}%
}

\begin{document}

\begin{figure}
\centering
\subfloat[A]{%
\mygrid{\includegraphics[trim = 10mm 10mm 70mm 20mm,clip,scale=0.15]{image1}}%
}\quad
\subfloat[A]{\mygrid{\includegraphics[trim = 10mm 10mm 70mm 20mm,clip,scale=0.15]{image1}}%
}\\
\subfloat[A]{\mygrid{\includegraphics[trim = 10mm 10mm 70mm 20mm,clip,scale=0.15]{image1}}%
}\quad
\subfloat[A]{\mygrid{\includegraphics[trim = 10mm 10mm 70mm 20mm,clip,scale=0.15]{image1}}%
}
\caption{Time Evolution}
\end{figure}

\end{document}

enter image description here

Moriambar
  • 11,466
Gonzalo Medina
  • 505,128