如何生成给定长度的令牌列表并在表格环境中使用它?

时间:2011-01-09 13:29:54

标签: latex

我正在尝试构建一个LaTeX环境,以便对于每个整数N,

\begin{mytab}{N}
% foo bar
\end{mytab}

将扩展为

\begin{tabular}{lr.....lr}
% foo bar
\end{tabular}

有N个令牌对“lr”。

这是我做这件事的可怜尝试。我觉得我正走在正确的轨道上 \mytokens是我想要的令牌列表。如果只有当我在最后一行的最后一行替换\junk \mytokens时才会有效...

\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
}

1 个答案:

答案 0 :(得分:1)

您可以使用*重复列定义:

\begin{tabular}{*{6}{lr}}
 %...
\end{tabular}