I want to use conditionals to fill a tabular
, but it fails. My MWE:
\documentclass{article}
\usepackage{environ}
\newcounter{mycounter}
\NewEnviron{montab}{%
\setcounter{mycounter}{0}
\newcommand{\mcItem}[1]{%
\stepcounter{mycounter}%
\ifcase \arabic{mycounter} % If counter = 0
\relax
\or % If counter = 1
##1 & %
\or % If counter = 2
##1 \\%
\or % If counter = 3
##1 &
\or % If counter = 4
##1
\fi
}
\begin{tabular}{cc}
\BODY
\end{tabular}
}
\begin{document}
\begin{montab}
\mcItem{premier}
\mcItem{deuxieme}
\mcItem{troisieme}
\mcItem{quatrieme}
\end{montab}
\end{document}
I hoped with this code to obtain the output :
premier deuxieme
troisieme quatrieme
I think the problem comes from the fact for example that a part of the conditional (the \ifcase
) is before a &
and the rest is after it. Since any cell of a tabular
forms a group, the different elements of the conditional lie in different groups.
- Did I understand the problem correctly?
- How to do it better? :)