Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

2 Answers 2

up vote 12 down vote accepted
\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}
share|improve this answer
    
thanks for the solution. This solution is also informative that lets me know the plain tex. –  xport Dec 23 '10 at 7:04
add comment

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).

share|improve this answer
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 '10 at 19:27
    
thanks for answering. I got a result without horizontal and vertical tabular rules after compiling your code. –  xport Dec 23 '10 at 0:03
2  
@xport: changing the class to article solves the problem (although I don't know why). –  Bruno Le Floch Mar 7 '11 at 20:33
    
@Bruno It puzzled me ever since! –  Yiannis Lazarides Mar 7 '11 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. –  Yiannis Lazarides Jun 7 '12 at 15:57
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.