I want to arrange EPS graphics (included via \includegraphics
) in a tabular
using \foreach
. Currently this is done without any loops like this:
\begin{tabular}{*5{>{\centering\arraybackslash}m{.15\textwidth}}}
$X_{40}$ & $X_{60}$ & $X_{80}$ & $X_{120}$ & $X_{160}$ \\
\includegraphics[width=.15\textwidth]{./testrun/testvar_type_X_40.eps}
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_X_60.eps}
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_X_80.eps}
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_X_140.eps}
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_X_160.eps} \\
\includegraphics[width=.15\textwidth]{./testrun/testvar_type_Xest_40.eps}
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_Xest_60.eps}
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_Xest_80.eps}
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_Xest_140.eps}
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_Xest_160.eps} \\
\end{tabular}
As you can see, the second and third row have some redundancy. Additionally in each row all columns differ only in the numbers 40, 60, 80, 140, 160. So my idea is, to use at least a \foreach
in each row to put the numbers in there.
My attempt doing so arose from https://tex.stackexchange.com/a/22276. However, using \includegraphics
in there does not seem to work (Argument of \reserved@a has an extra }
). This is the code used:
\documentclass[draft]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{array}
\usepackage{pgffor}
\usepackage{etoolbox}
\begin{document}
\let\tabularContent\empty
\newcommand{\plotChannels}{
\foreach \channel in {40,60,80,120,160}{
\begingroup\edef\x{
\endgroup\noexpand\gappto\noexpand\tabularContent{
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_X_\channel.eps}
}
}\x
}
\gappto\tabularContent{\\}
}
\plotChannels
\begin{tabular}{*6{>{\centering\arraybackslash}m{.15\textwidth}}}
$X_{40}$ & $X_{60}$ & $X_{80}$ & $X_{120}$ & $X_{160}$ \\
\tabularContent
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_Xest_40.eps}
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_Xest_60.eps}
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_Xest_80.eps}
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_Xest_140.eps}
& \includegraphics[width=.15\textwidth]{./testrun/testvar_type_Xest_160.eps} \\
\end{tabular}
\end{document}
Thanks for your help.
\documentclass{...}
and ending with\end{document}
.