fpantigny / nicematrix

The LaTeX package nicematrix
0 stars 1 forks source link

Adding custom code as an option for columns specifications #6

Open Basmah1961 opened 2 weeks ago

Basmah1961 commented 2 weeks ago

image

tabularray package has a key cmd to execute a command for every cell text. It is possible to use the legacy >{cmd} to provide similar commands, but it is neater to provide such option as a key for X column type. Also, I think it is good to provide hanging as an option for column specifiers

\documentclass[11pt, a4paper]{article}

\newcommand{\sampleText}{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullamnec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante. \par Donec ullamcorper, felis non sodales commodo, lectus velit ultrices augue, a dignissim nibh lectus placerat pede}

\usepackage{nicematrix}

\usepackage{tabularray}

\begin{document}

\noindent%
\begin{NiceTabularX}{\linewidth}{@{}l X[l,t]@{}}[hvlines, cell-space-limits=0pt]

    Text
    & 
    \setlength{\hangindent}{+1em}
    \sampleText
    \\

\end{NiceTabularX}

\bigskip

\noindent%
\begin{tblr}{colspec={@{}Q[l,h] Q[co=1,l,t,cmd=\setlength{\hangindent}{+1em}]@{}},
    rowsep=0pt,
    width=\linewidth,
    hlines, vlines
}

    Text
    & 
    \sampleText
    \\

\end{tblr}

\end{document}
fpantigny commented 2 weeks ago

The technic of >{...} provided by array is not similar to the key cmd of tabularray.

>{...} will insert tokens at the beginning of the cell, but those tokens are not able to grab the content of the cell as an argument for a LaTeX command. That means that it's not possible to write >{\fbox} with the expected result. Of course, it's possible to put declarative commands such as \bfseries or \color{white}.

In the tables of LaTeX (with the standard package array), one have to use the package collcell in order to be able to specify a command that will be applied to all the cells of a column. Since nicematrix relies on the arrays of the package array, the situation is the same for the environments of nicematrix.