An abstraction seems the best strategy. I define the \multipleimages
command with the syntax
\multipleimages
{<file name pattern>}
{<number of images per line>}[<correction>]
{<total number>}
In your case the call should be
\multipleimages{./img/img_#1}{5}{50}
or maybe
\multipleimages{./img/img_#1}{5}[0.8]{50}
The optional correction factor can be determined by trying to typeset reducing it until the float can find place in a page. In the example below I get
LaTeX Warning: Float too large for page by 11.14352pt on input line 45.
when the correction factor is set to 0.8
, but no such warning with 0.79
. The right factor depends on the vertical size of the images, which are supposed to have the same height.
The second example shows how to change the number of images per line.
There is no #1
in the first argument in examples 1 and 2 because I didn't want to create 50 different names. So, for the third example, I made four copies of example-image.pdf
named img1.pdf
, img2.pdf
, img3.pdf
and img4.pdf
in order to show that the first argument correctly interprets the given pattern.
\documentclass{article}
\usepackage{graphicx}
\ExplSyntaxOn
\NewDocumentCommand{\multipleimages}{mmO{1}m}
{% #1 = pattern for the image names
% #2 = number of images per line
% #3 = reduction factor (default 1)
% #4 = total number of images
\curious_multimg:nnnn { #1 } { #2 } { #3 } { #4 }
}
\int_new:N \l__curious_multimg_idx_int
\cs_new_protected:Nn \curious_multimg:nnnn
{
\cs_set:Nn \__curious_multimg_name:n { #1 }
\int_zero:N \l__curious_multimg_idx_int
\int_step_inline:nn { #4 }
{
\group_begin:
\renewcommand{\arraystretch}{0}
\begin{tabular}[t]{@{}c@{}}
\includegraphics[width=\fpeval{(#3)/(#2)}\columnwidth]{\__curious_multimg_name:n { ##1 }}
\\
\footnotesize\strut ##1
\end{tabular}
\group_end:
\int_compare:nT{\int_mod:nn{##1}{#2}==0}{\par\vspace{0.3ex}}
}
}
\ExplSyntaxOff
\begin{document}
\begin{figure}[p]
\centering
\multipleimages{example-image}{5}[0.79]{50}
\caption{Fifty images}
\end{figure}
\begin{figure}[p]
\centering
\multipleimages{example-image}{7}{50}
\caption{Fifty images}
\end{figure}
\begin{figure}[p]
\centering
\multipleimages{img#1}{2}{4}
\caption{Four images}
\end{figure}
\end{document}
\columnwidht
is that what you are asking about?\columnwidht
for\columnwidth