下面的代码片段不起作用:
\documentclass{minimal}
\usepackage{longtable}
\usepackage{ifthen}
\newcounter{xyz}
\setcounter{xyz}{0}
\begin{document}
\begin{longtable}{|*2{c|}}
\hline
\whiledo{\value{xyz}<10}%
{%
\thexyz & something\stepcounter{xyz} \\\hline%
}%
\end{longtable}
\end{document}
答案1
\documentclass{article}
\usepackage{longtable}
\newcounter{xyz}\newcounter{uvw}
\makeatletter
\newtoks\@tabtoks
\newcommand\addtabtoks[1]{\@tabtoks\expandafter{\the\@tabtoks#1}}
\newcommand*\resettabtoks{\@tabtoks{}}
\newcommand*\printtabtoks{\the\@tabtoks}
\makeatother
\pagestyle{empty}
\begin{document}
\resettabtoks
\loop\ifnum\theuvw<10\relax
\stepcounter{uvw}
\addtabtoks{\thexyz & something\stepcounter{xyz} \\\hline}%
\repeat
\begin{longtable}{|*2{c|}}\hline
\printtabtoks
\end{longtable}
\end{document}
答案2
尝试这个:
\documentclass{article}
\usepackage{longtable}
\usepackage{ifthen, xspace}
\newcounter{xyz}
\setcounter{xyz}{0}
\begin{document}
\def\and{&\xspace}
\begin{longtable}{|*2{c|}}
\hline
\whiledo{\value{xyz}<10}%
{%
\thexyz \and something\stepcounter{xyz} \\\hline%
}%
\end{longtable}
\end{document}
编辑从最小类别更改为文章(参见评论)。