Tabularray – How to Redefine Double Backslash for Multiline Cells in Tabularray

tabularray

When using multiline cells with tabularray like in the example below, I have the problem that my editor (emacs) recognizes the \\ that indicate a newline in a cell as the end of a row and thus messes up aligning the table in the editor. So is there a way to use another command instead of \\ for the multiline cells or map it to another macro. I tried \newcommand{\nl}{\\}, but this doesn' work (it stretches the table to the right).

\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{colspec={clr},hlines}
    one & {left\\leftttt} & three          \\
    one & two             & {right\\rightttt} \\
\end{tblr}
\end{document}

(Example from here).

Best Answer

You can use your \nl command to break multiline cells by using varwidth library of tabularray package (and you don't need to enclose them with curly braces):

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{varwidth}
\SetTblrInner[tblr]{measure=vbox}
\newcommand{\nl}{\\}
\begin{document}

\begin{tblr}{colspec={clr},hlines}
  one                 & left\nl leftttt & three             \\
  center\nl centerrrr & two             & right\nl rightttt \\
\end{tblr}

\bigskip

\begin{tblr}{colspec={clr},hlines}
  one                 & {left\\leftttt} & three             \\
  {center\\centerrrr} & two             & {right\\rightttt} \\
\end{tblr}

\end{document}

enter image description here