2

I just wanted to insert n empty rows using tlbr like this:

\documentclass[letterpaper]{article} \usepackage{expl3} \ExplSyntaxOn \cs_new_eq:NN \makerows \prg_replicate:nn \ExplSyntaxOff \usepackage{tabularray} \begin{document} With tabular: \begin{tabular}{|c|c|c|c|} \hline a & b & c & d \\\hline \makerows{5}{ & & & \\\hline} \end{tabular} With tblr: \begin{tblr}{|c|c|c|c|} \hline a & b & c & d \\\hline %\makerows{5}{ & & & \\\hline} %% Gives % ! Misplaced alignment tab character &. % <argument> & % & & \\\hline \end{tblr} \end{document} 

Using tabular it works, using tblr it doesn't . How can I fix this?

3
  • 1
    See my answer to a question yesterday concerning a similar issue with tblr, tblr needs to see the & in advance, I tried using expand=\makerows in your question but it still doesn't work, hopefully someone else can help!: tex.stackexchange.com/a/691258/273733 Commented Jul 17, 2023 at 13:01
  • 1
    @JamesT: In the meantime I found some variations which work, see my answer below. But I don't really understand why some work and others don't. Commented Jul 17, 2023 at 18:55
  • The lua version is interesting how that works, will try that in the future, nice workaround Commented Jul 17, 2023 at 19:40

1 Answer 1

1

This seems to work:

\documentclass{article} \usepackage[T1]{fontenc} \usepackage{expl3,xparse} \usepackage{tabularray} \UseTblrLibrary{functional} \IgnoreSpacesOn \prgNewFunction \makerows {m} { \intReplicate {#1} {{} & & & \\\hline } } \IgnoreSpacesOff \begin{document} With tabular: \begin{tabular}{|c|c|c|c|} \hline a & b & c & d \\\hline \makerows{5} \end{tabular} With tblr: \begin{tblr}[evaluate=\makerows]{|c|c|c|c|} \hline a & b & c & d \\\hline \makerows{5} \end{tblr} \end{document} 

Adapted from the example of the tabularray manual on page 46. However I am not quite sure why I need the empty {} in the definition of my empty row.

Nevertheless I want to understand why the initial latex3 approach didn't work. The problem seems to be related to the replicate function.

Edit

Using lualatex seems to work with the expand-key as mentioned by @JamesT in the comment above:

\documentclass{article} \usepackage{tabularray} \usepackage{luacode} \begin{luacode} function makerows(n) for i = 1, n do tex.sprint("& & & \\\\\\hline") end end \end{luacode} \begin{document} \begin{tblr}[expand=\directlua]{c|c|c|c} a & b & c & d \\\hline \directlua{makerows(10)} \end{tblr} \end{document} 

Edit 2

I also tried pythontex which does not work even with the expand key:

\documentclass{article} \usepackage{tabularray} \usepackage[gobble=auto]{pythontex} \begin{pycode} def makerows(n): for i in range(0,n): print(r"& & & \\\hline") \end{pycode} \begin{document} \begin{tblr}[expand=\pyc]{c|c|c|c} a & b & c & d \\\hline \pyc{makerows(3)} \end{tblr} \end{document} 

I guess it doesn't work, because

Printed content is saved in a file and then included via \InputIfFileExists. But \InputIfFileExists is not expandable

as described here.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.