I'm trying to fill a table by iterating through predefined data and experience errors with both & (next column) and \\ (next row) using code like follows:
\begin{document}
% \foreach \s in \schedule {
% \textbf{\GetListMember{\s}{1}:} \GetListMember{\s}{2} \\
% }
\begin{tabular}{ll}
\foreach \s in \schedule {
\textbf{\GetListMember{\s}{1}} & \GetListMember{\s}{2} \\
}
\end{tabular}
\end{document}
The complete example:
\documentclass[12pt, a4paper]{article}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{pgffor}%
\usepackage{xstring}%
%
%\tracingall%
%
\setlength{\parindent}{0in}%
%
\newcommand*{\GetListMember}[2]{%
\edef\dotheloop{%
\noexpand\foreach \noexpand\a [count=\noexpand\i] in {#1} {%
\noexpand\IfEq{\noexpand\i}{#2}{\noexpand\a\noexpand\breakforeach}{}%
}}%
\dotheloop%
}%
%
\edef\schedule {%
%{{Title},{Description}},%
{{Ipsum},{Pellentesque mauris mauris, feugiat ut.}},%
{{Lorem},{Integer viverra blandit magna, in imperdiet sapien sollicitudin at.}},%
{{Presen},{Nunc eu euismod nunc. Sed tincidunt, sem eu facilisis rhoncus.}},%
{{Magna},{Phasellus velit dui, tristique at sem et, finibus volutpat sapien.}},%
{{Vide},{Fusce in sapien mi. Vestibulum sed venenatis risus. Ut turpis dui.}},%
{{Albi},{Proin dolor mauris, pellentes sem convallis. Suspendisse elementum.}},%
{{Cosco},{Integer in molestie diam. Donec sapien, porta lacinia gravida ac.}}%
}%
\begin{document}
% \foreach \s in \schedule {
% \textbf{\GetListMember{\s}{1}:} \GetListMember{\s}{2} \\
% }
\begin{tabular}{ll}
\foreach \s in \schedule {
\textbf{\GetListMember{\s}{1}} & \GetListMember{\s}{2} \\
}
\end{tabular}
\end{document}
pdflatex states:
! Extra }, or forgotten \endgroup.
<template> \unskip \hfil }
\hskip \tabcolsep \endtemplate
l.36 }
Unfortunately, tracing the build with \tracingall runs endlessly and I'm not familiar with macros.
The build succeeds with documents like:
\begin{document}
% \foreach \s in \schedule {
% \textbf{\GetListMember{\s}{1}:} \GetListMember{\s}{2} \\
% }
\begin{tabular}{l}
\foreach \s in \schedule {
\textbf{\GetListMember{\s}{1}} \GetListMember{\s}{2}
}
\end{tabular}
\end{document}
and:
\begin{document}
\foreach \s in \schedule {
\textbf{\GetListMember{\s}{1}:} \GetListMember{\s}{2} \\
}
% \begin{tabular}{ll}
% \foreach \s in \schedule {
% \textbf{\GetListMember{\s}{1}} & \GetListMember{\s}{2} \\
% }
% \end{tabular}
\end{document}
You can find the discussion about GetListMember here: Macro to access a specific member of a list
I'm happy with every solution that enables building a table by iterating and accessing two dimensional data.

\foreachin a table cell and end it in another. – egreg Jan 27 '19 at 22:12