3

I have a command that generates a table row for insertion into a tblr environment as shown below:

\documentclass{book}
\usepackage{tabularray}
\begin{document}

\newcommand\MyRow[2]{ #1 & #2 \ }

\begin{tblr}{l l} A & B \ C & D \ %\MyRow{E}{F} % Fails here with "Misplaced alignment tab character &" \end{tblr}

\end{document}

The command used to work with tabu but with tblr it produces an error that the alignment character & is misplaced:

Misplaced alignment tab character &.

I tried overriding the category code of & with \catcode38=12 but it didn't help. How do I generate a tblr row from a custom command?

1 Answers1

7

According to section "3.2.3 Expand Macros First" of the manual of the package tabularray you need to use the key expand=\MyRow. You only get top-level-expansion of \MyRow:

\documentclass{book}
\usepackage{tabularray}
\begin{document}

\newcommand\MyRow[2]{#1 & #2 \}

\begin{tblr}[expand=\MyRow]{l l} A & B \ C & D \ \MyRow{E}{F}% Does not fail with "Misplaced alignment tab character &". \end{tblr}

\end{document}

enter image description here


The question "tabularray: How to comment out some rows using \if condition inside a table stored in a macro?" and its answers provide some trickery for getting more control over expansion.

Ulrich Diez
  • 28,770