# how to use \loop … \repeat to generate an arbitrary number of rows in a table [duplicate]

Possible Duplicate:
Copy table row n times

The code below is intended to produce a table with 3 columns and 3 rows (one heading and two empty rows) but it can be seen that it doesn't work.

\documentclass{article}

\newcommand\emptytable[1]{%
\def\emptyrow{ & & \\ \hline}
\newcount\rows
\begin{tabular}{|c|c|c|}
\hline
A & B & C \\
\hline
%% the following 2 lines create 2 empty rows
%% \emptyrow
%% \emptyrow
%% the following loop doesn't work
\end{tabular}
}

\begin{document}
\emptytable{2}
\end{document}


Why does it not work?

-

## marked as duplicate by Ryan Reich, Werner, barbara beeton, Thorsten, GuidoDec 31 '12 at 17:06

You can't start a \loop in a cell and end it in another, because table cells form groups. There are other examples in the site: 1; 2 –  egreg Dec 31 '12 at 15:31

While egreg's comment applies, you can make your automation idea work via pgfplotstable package. Here is a simple example

\documentclass{article}
\usepackage{pgfplotstable}

\newcommand{\myemptytable}[1]{
\pgfplotstableset{
create on use/new1/.style={},
create on use/new2/.style={},
create on use/new3/.style={}
}
\pgfplotstabletypeset[
columns={new1,new2,new3},
string type,
columns/new1/.style={column name=A},
columns/new2/.style={column name=B},
before row=\hline,
every last row/.style={after row=\hline},