I have 25 images (00.jpg, 01.jpg, .... 24.jpg) that I want to display in a 5x5 grid. Is there a way to do this automatically? Or do I have to make a table and write out all of the file names?
Thanks,
Dave
Graphics, Figures & Tables ⇒ Automatically generate a grid of images
NEW: TikZ book now 40% off at Amazon.com for a short time.

Automatically generate a grid of images
Hi, Dave
you could rename your images as 1-1.jpg, 1-2.jpg, ... , 1-5.jpg (those who will appear in the first row); 2-1.jpg, 2-2.jpg, ... , 2-5.jpg (those who will appear in the second row); ... 5-1.jpg, 5-2.jpg, ... , 5-5.jpg (those who will appear in the fifth row) and then use, for example, two nested \foreach constructs (of the PGF/TikZ package) to achieve the desired result. The following code illustrates schematically this approach:
Edit: here's the same idea implemented with \whiledo commands from the ifthen package:
you could rename your images as 1-1.jpg, 1-2.jpg, ... , 1-5.jpg (those who will appear in the first row); 2-1.jpg, 2-2.jpg, ... , 2-5.jpg (those who will appear in the second row); ... 5-1.jpg, 5-2.jpg, ... , 5-5.jpg (those who will appear in the fifth row) and then use, for example, two nested \foreach constructs (of the PGF/TikZ package) to achieve the desired result. The following code illustrates schematically this approach:
Code: Select all
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\foreach \i in {1,...,5}{
\foreach \j in {1,...,5}{
\noindent\includegraphics{\i-\j}
}\\
}
\end{document}
Code: Select all
\documentclass{article}
\usepackage{graphicx}
\usepackage{ifthen}
\begin{document}
\newcounter{myrow}
\newcounter{mycolumn}
\setcounter{myrow}{1}
\whiledo{\themyrow<6}{
\whiledo{\themycolumn<5}{
\stepcounter{mycolumn}
\noindent\includegraphics{\themyrow-\themycolumn}
}\setcounter{mycolumn}{0}\\\stepcounter{myrow}
}
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
-
- Posts: 60
- Joined: Tue Sep 30, 2008 9:24 pm
Re: Automatically generate a grid of images
Yes, perfect! Exactly what I was looking for, thanks!
Dave
Dave