How to Repeat in Latex 

Newsgroups: comp.text.tex
From: mcdan...@bbn.com (Greg McDaniel)
Date: 1995/04/13

How does one repeat something a number times. For an example, suppose I had an array with 30 columns, all centered, and I want to use a command like:

\begin{array}{cccc .... (30 times)}

How to Repeat in Latex 

> \begin{array}{cccc .... (30 times)}

I think you're looking for something like:

\begin{array}{*{30}{c}}

Gary A. Churchh

How to Repeat in Latex 

create a macro using the ifthen package …it in the base directory. In it you will find commands such as \ifthenelse \whiledo etc.

Walter Tautz

Newsgroups: comp.text.tex
From: David R <angel_ov_no...@tiscali.co.uk>
Date: Thu, 14 Dec 2006

Hi,

\begin{array}[pos]{|*{5}{|c|}}
& & & & & \\
\end{array}

allows me to specify |c| columns 5 times.

My questions is can I repeat the data to go into the columns in the same way? Thus

\begin{array}[pos]{|*{5}{|c|}}
something1 & *{4}{& something2} \\
\end{array}

David R

There are ways, but they are not part of tabular/array. Moreover, it gets very tricky when spanning multiple array cells because of local grouping. Unless this is really important, I suggest relicating the data with your text editor.

Donald Arseneau

\documentclass{article}
\makeatletter
\newcommand\replicate[2]{%
   \ifnum#1>\z@ \expandafter\@firstofone
   \else
     \expandafter\@gobble
   \fi
   {#2\expandafter\replicate\expandafter{\number\numexpr#1-1\relax}{#2}}%
}

\makeatother
\begin{document}
\begin{tabular}{|*{5}{|c|}}
something1 \replicate{4}{& something2} \\
\end{tabular}
\end{document}

Morten Hogholm

> Thankyou very much.  That is outstanding.  I could never have done that
> in a year.  Could this be made into a \usepackage{arrayinnards.sty} so
> that everybody could do this?

Well, it's more of a utility macro which has numerous uses.

The expl3 code http://www.ctan.org/tex-archive/help/Catalogue/entries/expl3.html contains various forms of such macros if you are interested in understanding how they can be constructed.

documented on: 15 Dec 2006, Morten Hogholm

Latex file to create an empty table 

\documentclass{article}

\makeatletter
\newcommand\replicate[2]{%
   \ifnum#1>\z@ \expandafter\@firstofone
   \else
     \expandafter\@gobble
   \fi
   {#2\expandafter\replicate\expandafter{\number\numexpr#1-1\relax}{#2}}%
}
\newcommand\RowCnt{5}
\newcommand\ColCnt{5}
\makeatother

\begin{document}
\thispagestyle{empty}  % no page number

\begin{tabular}{|l|\replicate{\RowCnt}{c|}}\hline
something1 \replicate{\RowCnt}{& ~} \\ \hline
something2 \replicate{\RowCnt}{& ~} \\ \hline
\end{tabular}

\end{document}

documented on: 2007.07.02, T

repeating rows in a table 

Newsgroups: comp.text.tex
From: Kris Luyten <kris.luy...@luc.ac.be>
Date: Fri, 1 Feb 2002

Is there a package that allows to repeat (copy) a row in a table n times.

I want to say something like:

\begin{tabular}{l|l|l}\hline
blabla & blabla & blabla \\ \hline
\repeat_this_row_n_times &&&\\\hline
\end{tabular}

repeating rows in a table 

> > [...]
> > \theline
> > \theline
> > \theline
> > \theline
> > \end{tabular}
> That is not repeat "n" times, like my question stated.  I want to
> avoid the copy-paste stuff and "repeat" the LaTeX command like in a
> loop in a regular programming language.

Just like in a regular programming language, you'd do

\def\nlines#1{\expandafter\nlineii\romannumeral\number\number #1 000\relax}
\def\nlineii#1{\if#1m\expandafter\theline\expandafter\nlineii\fi}

and then in the document you can say

\def\theline{whatever&you&want\\}
\begin{tabular}{l|l|l}\hline
\nlines{13}
\end{tabular}

Is this more similar to what you need?

David Kastrup

repeating rows in a table 

> Is this more similar to what you need?

Yes! This works great.

Kris Luyten