lvjr / tabularray

Typeset tabulars and arrays with LaTeX3
https://ctan.org/pkg/tabularray
258 stars 22 forks source link

Is it possible to copy table row n times? #222

Closed user7598 closed 2 years ago

user7598 commented 2 years ago

I'm trying to create large blank table. With tabular I can use \prg_replicate:nn:

\ExplSyntaxOn

\newcommand{\replicate}[2]{ \prg_replicate:nn {#1}{#2} }

\ExplSyntaxOff

\begin{tabular}{|c|c|}
\hline
tabular & tabular \\ \hline
\replicate{3}{a & b \\ \hline}
\end{tabular}
sample-tabular

But with tabularray I got multiline cell without hlines instead of multiple rows

\begin{tblr}
[expand=\replicate]
{hlines,vlines,colspec={QQ}}
tabularray & tabularray \\
\replicate{2}{a & b \\ }
\end{tblr}
sample-tabularray

Is it possible to achieve this behaviour with tabularray instead of copy and pasting?

lvjr commented 2 years ago

Same as issue #201, you need to collect table body outside the table first.

\documentclass[11pt]{article}
\usepackage{tabularray}

\ExplSyntaxOn
\newcommand{\replicate}[2]{
  \tl_set:Nx \tblrbody {\prg_replicate:nn {#1}{#2}}
}
\ExplSyntaxOff

\begin{document}

\replicate{3}{a & b \\ }
\begin{tblr}[expand=\tblrbody]{hlines,vlines,colspec={QQ}}
tabularray & tabularray \\
\tblrbody
\end{tblr}

\end{document}