4

Please, consider the following MWE:

\documentclass[border=3mm]{standalone}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document} \begin{tblr}{hlines, vlines, cell{1}{2-4} = {bg=gray9} } 1 & Beta & Gamma & Delta \ 2 & Beta & Gamma & Delta \ 3 & \SetCell[c=2]{bg=red8} Beta & Gamma & Delta \ \end{tblr} \end{document}

which produce

enter image description here

Question: does exist settings for \SetCell (used in the third row) equivalent to cell{3}{2-3} = {bg=red8} used in tblr options? I like to get the same result with use of one \SetCell.

Zarko
  • 296,517
  • I don't think that is possible since \SetCell locks the indices i and j to whereever the command is called. Maybe \SetRow accepts an optional argument to specify only certain columns? – marv Jan 18 '22 at 08:32
  • @marv, I wonder about is. In manula on page 17 is noted " In fact, table command \SetCell[]{} at the beginning of cell at row i and column j is the same as table option cell{i}{j}={}{}. Also, table command \SetCells[]{} at the beginning of some cell is the same as table option cells={}{}." , so I hope that this is somhow possible or what is more like that I mussunderstand this statement :-( – Zarko Jan 18 '22 at 08:37
  • yeah, i also looked at this paragraph. Don't really understand the <span> argument of \SetCells (or cells). It doesn't make sense to set e.g. c=2 for every cell. Also using this option e.g. with cells=[c=2]{bg=red8} produces an error for me. Reading the code, the optional argument of \SetCells (or cells) is just passed to every cell. I guess this works in principle, but it is not sensible to set the <span> parameters c and r globally for every cell. – marv Jan 18 '22 at 09:09

2 Answers2

6

Here is a function that can do this. It gives the same result as your code. As far as I can see there is no similar functionality in tabularray itself.

\documentclass[border=3mm]{standalone}
\usepackage{xcolor}
\usepackage{tabularray}

\ExplSyntaxOn

% Usage: \SetCellRange[r=#rows,c=#cols]{style}. Default: r=1,c=1 \NewTableCommand \SetCellRange [2] []
{ \tl_set:Nn \l__tblr_row_span_num_tl { 1 } \tl_set:Nn \l__tblr_col_span_num_tl { 1 } \keys_set:nn { tblr-cell-span } { #1 } \int_set:Nn \l_tmpa_int { \value{rownum} + \l__tblr_row_span_num_tl - 1 } \int_set:Nn \l_tmpb_int { \value{colnum} + \l__tblr_col_span_num_tl - 1 } \tblr_set_cell:nnnn { \value{rownum}-\int_use:N \l_tmpa_int } { \value{colnum}-\int_use:N \l_tmpb_int } { } { #2 } }

\ExplSyntaxOff

\begin{document} \SetTblrTracing{all} \begin{tblr}{hlines, vlines} 1 & \SetCellRange[c=3]{bg=gray9} Beta & Gamma & Delta \ 2 & Beta & Gamma & Delta \ 3 & \SetCell[c=2]{bg=red8} Beta & Gamma & Delta \ \end{tblr} \end{document}

  • Thank you very much. I will test your suggestion at late evening, so faR +1 :-) – Zarko Jan 18 '22 at 15:06
  • The \SetTblrTracing{all} is there only for debugging. – Pieter van Oostrum Jan 18 '22 at 15:39
  • It works! Thank you very much again! Now I have only one wish: that package author include your solution to next package realize. and make note about cell and \SetCell on page 17 (version 2021Q) more clear (see my comment below question). – Zarko Jan 18 '22 at 16:45
  • You can put a request on https://github.com/lvjr/tabularray/issues – Pieter van Oostrum Jan 18 '22 at 18:34
  • @Zarko Sorry, I am not going to add this command to the package. But I will update the documentation for \SetCells command. – L.J.R. Jan 19 '22 at 02:57
3

I would suggest to define a short command for this usage:

\documentclass[border=3mm]{standalone}

\usepackage{xcolor} \usepackage{tabularray}

\NewTableCommand\SC{\SetCell{bg=red8}}

\begin{document}

\begin{tblr}{hlines, vlines, cell{1}{2-4} = {bg=gray9} } 1 & Beta & Gamma & Delta \ 2 & Beta & Gamma & Delta \ 3 & \SC Beta & \SC Gamma & Delta \ \end{tblr}

\end{document}

enter image description here

L.J.R.
  • 10,932