How to use a command for a row with tabularray

longtablemacrostablestabularray

I want to switch from longtable to tabularray due to its more granular customization.

In longtable I can use a command with an argument which sets the whole row (with &).
However tabularray does not like this and throws me an error.

MWE

\documentclass{scrartcl}

\usepackage{tabularray}
\usepackage{longtable} % for comparison


\newcommand{\myrow}[1]{
  Hello #1 & my name is #1 \\
}

\NewTableCommand{\myRow}[1]{
  Hello #1 & my name is #1 \\
}


\begin{document}

\begin{longtblr}{colspec={ll}}
  Hello & world \\
 % \myrow{Peter} % does not work
 % \myRow{Hans} % does not work either
\end{longtblr}


\begin{longtable}{ll}
  Hello & world \\
  \myrow{Peter}
  \myrow{Hans}
\end{longtable}

\end{document}

enter image description here

Best Answer

You can use the expand option.

\begin{longtblr}[expand=\myrow]{colspec={ll}}
  Hello & world \\
 \myrow{Peter} % does not work
 \myrow{Hans} % does not work either
\end{longtblr}

I think only one such macro can be expanded per table. It must be defined with \newcommand, not with \NewTableCommand.

Related Question