在图像数组中的每个图像上绘制网格

在图像数组中的每个图像上绘制网格

当我需要图形阵列中每张图片上的单独网格时,请查看我所写的内容。与预览问题相比在图像阵列上绘制网格。现在的问题是为什么在这种情况下我不能使用\subfloatbefore \includegraphics?我想使用,因为我需要在每个图像下面添加标题。另外我猜应该有一些解决方案来优化此代码,比如定义新命令而不是在数组的每个元素上编写网格代码,因为我在原始文档中有更多数组。

\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}

答案1

用于回答另一个问题的代码的变体;的参数\mygrid是将接收网格的对象(在本例中,是\includegraphics包含图像的标准命令):

\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}

在此处输入图片描述

相关内容