3

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
    \loop\relax\ifnum\rows<#1 \emptyrow\advance\rows by1\repeat
  \end{tabular}
}

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

produces enter image description here instead of enter image description here

Why does it not work?

Ernest A
  • 2,773
  • 5
    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

1 Answers1

3

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={}
}
{\pgfplotstablenew[columns={new1,new2,new3}]{#1}\loadedtable
\pgfplotstabletypeset[
columns={new1,new2,new3},
string type,
columns/new1/.style={column name=A},
columns/new2/.style={column name=B},
columns/new3/.style={column name=C,column type/.add={}{|}},
before row=\hline,
every last row/.style={after row=\hline},
column type/.add={|}{}%
]\loadedtable}
}

\begin{document}

\myemptytable{3}
\myemptytable{6}
\end{document}

enter image description here

percusse
  • 157,807