How can I generate token list of given length and use it in tabular environment?
I am trying to build a LaTeX environment such that for every integer N,
\begin{mytab}{N}
% foo bar
\end{mytab}
would expand to
\begin{tabular}{lr.....lr}
% foo bar
\end{tabular}
with N token pairs "lr".
Here is my poor attempt at doing it. I feel I am on the right track开发者_开发技巧, as
\mytokens
is the token list I want. If only it would work when I replace the \junk
by \mytokens
on the next to last line...
\newcounter{ct}
\newenvironment{mytab}[1]{%
\setcounter{ct}{#1}
\newcommand{\mytokens}{%
\ifthenelse{\thect>0}{\addtocounter{ct}{-1}lr\mytokens}{}
}
\def\junk{lrlrlrlrlrlr}
\expandafter\tabular\expandafter{\junk}%
}{
\endtabular
}
You can repeat column definitions with *
:
\begin{tabular}{*{6}{lr}}
%...
\end{tabular}
精彩评论