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.

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?

share|improve this question

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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 Answer 1

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

share|improve this answer

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