5

Assume you have pictures images=["1.png", "2.png", "3.png", ..., "50.png"];. You would like to loop them to a single tex document such that you get nice captions. I think it may be possible with Tikz. Minimum pseudocode code

\documentclass{article}
\usepackage{graphicx}
\begin{document}
%images=["1.png", "2.png", "3.png", ..., "50.png"]; 
%% Loop here all images; for i in images
\begin{figure}
\center
\includegraphics[scale=0.3]{"${i}"}
\caption{"Image "${i}"."}
%% end
\end{figure}
\end{document}

OS: Debian 8.5
TeXLive: 2016 (not apt-get one)

9

there are lots of loop implementations, for example

enter image description here

\documentclass{article}
\usepackage[demo]{graphicx}
\newcount\ii
\begin{document}
%images=["1.png", "2.png", "3.png", ..., "50.png"]; 
%% Loop here all images; for i in images
\loop
\ifnum\ii<50
\advance\ii by 1
\begin{figure}
\centering% not \center!
\includegraphics[scale=0.3]{\ii.png}
\caption{Image \the\ii.}
%% end
\end{figure}
\repeat
\end{document}
  • Always a good idea to initialize your counter (but only necessary if you have to repeat this code later). – Dan Nov 2 '16 at 20:00
  • How can you have 8x2 structure? That is having two figures at the same row. Is this scalable for it? - - Assume you have 2 files which all have 8 pictures. Have one file images in first column and second file images in the second column. – Léo Léopold Hertz 준영 Nov 15 '16 at 18:06
8

Since you asked for TikZ. (Well, if you're not using TikZ for anything else you can get away with loading just the pgffor package.)

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{pgffor}
\begin{document}
\foreach \ii in {1,...,50} {
\begin{figure}
\centering% not \center!
\includegraphics[scale=0.3]{\ii.png}
\caption{Image \ii.}
\end{figure}
} % closing brace for loop
\end{document}

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.