# How to get rid of these excessive rules?

\documentclass{article}%cannot be minimal
\usepackage{longtable}
\usepackage{ifthen, xspace}
\newcounter{xyz}
\setcounter{xyz}{1}
\def\and{&\xspace}
\begin{document}

\begin{longtable}{|*2{c|}}\hline
\whiledo{\value{xyz}<6}%
{\thexyz \and something\stepcounter{xyz} \\\hline}
\end{longtable}

\end{document}

-

This also removes the last two vertical lines:

\newcommand*{\condition}{\value{xyz}<6}
\begin{longtable}{|*2{c|}}\hline
\whiledo{\condition}%
{\thexyz \and something\stepcounter{xyz}%
\ifthenelse{\condition}{\\\hline}{\\\hline\end{longtable}}}


It's funny that these lines appear if I take \\\hline out of this \ifthenelse, similar if I put \end{longtable} after that (even with % before the line break). And, actually, I don't like ending an environment within a loop construction.

-
+1 but the coding workflow is so cryptic. :-) Waiting for another cleaner solution. –  xport Jun 18 '11 at 16:45

From the booktabs package documentation:

2 The layout of formal tables

You will not go far wrong if you remember two simple guidelines at all times:

1. Never, ever use vertical rules.

2. Never use double rules. These guidelines may seem extreme but I have never found a good argument in favour of breaking them. For example, if you feel that the information in the left half of a table is so different from that on the right that it needs to be separated by a vertical line, then you should use two tables instead.

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{ifthen, xspace}

\newcounter{xyz}
\def\and{&\xspace}

\begin{document}

\begin{longtable}{>{\stepcounter{xyz}\thexyz}cc}
\toprule
\whiledo{\value{xyz}<5}
{\and something \\}
& \xspace something \\
\bottomrule
\end{longtable}

\end{document}

-
+1 for suggesting the booktabs, but it is the same as what doncherry did. –  xport Jun 18 '11 at 16:46
@xport: in a sense, yes. But with my code I also wanted to show that you can move let the table format specification handle the counter. –  Gonzalo Medina Jun 18 '11 at 16:49
Yes. Of course but I have been using it for years. tex.stackexchange.com/questions/7208/… –  xport Jun 18 '11 at 16:59
\documentclass{article}%cannot be minimal
\usepackage{longtable}
\usepackage{ifthen, xspace}
\newcounter{xyz}
\setcounter{xyz}{1}
\def\and{&\xspace}
\begin{document}

\begin{longtable}{|*2{c|}}\hline
\whiledo{\value{xyz}<5}%
{\thexyz \and something\stepcounter{xyz} \\\hline}%
\thexyz \and something\stepcounter{xyz}\\\hline%
\end{longtable}

\end{document}

-
+ 1 but I actually want all row constructions to be in a single looping body. –  xport Jun 18 '11 at 16:28
@xport: Well, I guess Stefan's answer solves that. If you just wanna make sure any changes you make to the table row get transferred to the last row as well, we could define a \newcommand{\makerow}{\thexyz \and something\stepcounter{xyz}\\\hline} that is called in the loop body and once afterwards. –  doncherry Jun 18 '11 at 16:42