18

The following code snippet does not work:

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

2 Answers 2

18
\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}
1
  • thanks for the solution. This solution is also informative that lets me know the plain tex. Dec 23, 2010 at 7:04
9

Try this:

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

Edit Changed from minimal class to article (see comments).

6
  • 1
    I don't think that's the right way to do things. I'm not sure exactly what's going on here, but the rules don't appear so something fishy is going on.
    – TH.
    Dec 22, 2010 at 19:27
  • thanks for answering. I got a result without horizontal and vertical tabular rules after compiling your code. Dec 23, 2010 at 0:03
  • 2
    @xport: changing the class to article solves the problem (although I don't know why). Mar 7, 2011 at 20:33
  • @Bruno It puzzled me ever since! Mar 7, 2011 at 23:25
  • 1
    @Forgiver Yes, it was due to the OP having used the minimal class. There was a follow up question by Bruno, will find it out a bit later and post the link. Jun 7, 2012 at 15:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .