2

enter image description here

\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}
lockstep
  • 250,273
Display Name
  • 46,933

3 Answers3

3

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}
David Carlisle
  • 757,742
Gonzalo Medina
  • 505,128
  • +1 for suggesting the booktabs, but it is the same as what doncherry did. – Display Name 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. http://tex.stackexchange.com/questions/7208/how-to-vertically-center-the-text-of-the-cells/7227#7227 – Display Name Jun 18 '11 at 16:59
3

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.

Stefan Kottwitz
  • 231,401
1
\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}
doncherry
  • 54,637
  • @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