Latex foreach multiple figures loop
Using Latex, many times you want to print multiple figures that have similar names like figure_1.pdf, figure_2.pdf etc…
Instead of hardcoding everything, the foreach
package saves lives!
More specifically, you can write something like this:
\begin{figure}[H]
\centering
\foreach \n in {1,3,5,10,20}{
\begin{subfigure}{.18\linewidth}
\centering
\includegraphics[width=\textwidth]{figs/question_9_\n}
\subcaption{\n Trees}
\end{subfigure}
}
\caption{RF various number of trees evaluation.}
\end{figure}
Tags: efficiently, figures, for, foreach, latex, loop, multiple, print, subfigures
Trackback from your site.
cla4speed
| #
Your article is well explained and objective! Thanks.
But the name of the package is not “foreach”. It took me some time to find out why my code was crashing. But because the package needed is calle “pgffor”. Information I got from here: https://texblog.org/2015/10/09/automated-sub-figure-generation-using-a-loop-in-latex/
I thought maybe you would like to know…