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
\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