# How to insert N images using TikZ's \foreach?

I'd like to avoid having to copy & paste the same code 50 times in my input file, so I'm trying to use the automation offered by TikZ's \foreach.

I do not know why this code generates 101 errors. The first one is that an extra } was used.

\begin{tikzpicture}
\matrix[row sep=1mm,column sep=5mm] {
\foreach \y in {1,...,50} {
\node (left) {\includegraphics[width=0.49\textwidth {images/S001_GUT1_COR_T2/Original/15}}; &
\node [right=of left] {\includegraphics[width=0.49\textwidth {images/S001_GUT1_COR_T2/Segmented/15}}; \\
};
};
\end{tikzpicture}


Can you help me?

I have found and alternative to my question. But know I have another problem: how can I split the contents of one tikzpicture in more than one page?

\begin{tikzpicture}[font=\small\sffamily]
\node (row1) {\includegraphics[width=0.49\textwidth]{images/Original/1}};
\node[left=0mm of row1]  {\includegraphics[width=0.49\textwidth]{images/Segmented/1}};
\foreach \i [remember=\i as \lastx (initially 1)] in {2,...,10} {
\node[below=0mm of row\lastx] (row\i) {\includegraphics[width=0.49\textwidth]{images/Original/\i}};
\node[left= 0mm of row\i]  {\includegraphics[width=0.49\textwidth]{images/Segmented/\i}};
};


Just use a center environment. There's no need to do complicated positioning for images that all have the same dimensions.

\documentclass{article}
\usepackage{graphicx}
\usepackage{pgffor} % \foreach
\begin{document}

\begin{center}
\foreach \i in {1,2,...,10} {
\includegraphics[width=0.49\textwidth]{images/Original/\i}\hfil
\includegraphics[width=0.49\textwidth]{images/Segmented/\i}\par\smallskip
}
\end{center}
\end{document}