lvjr / tabularray

Typeset tabulars and arrays with LaTeX3
https://ctan.org/pkg/tabularray
253 stars 22 forks source link

How to have SetCell reset format #448

Closed jonhall closed 10 months ago

jonhall commented 10 months ago

I'd like the SetCell style to remove the initial '>{Indent:}', as it does the intermediate '|'.

Is that it doesn't a bug or a feature?

\documentclass{article}

\usepackage{tabularray}

\begin{document}
\begin{tblr}{|>{Indent:}X[3]|X[8]|}%%\quad indent for non-SetCell row
  Alpha & Beta\\
  \SetCell[c=2]{l}{Double width row; don't want Indent:}\\
\end{tblr}
\end{document}
muzimuzhi commented 10 months ago

Using >{<text>} in colspec is equivalent to setting column key preto=<text>, and unfortunately currently effects of preto and appto always accumulate hence there's no user interface to reset them.

Below is an attempt. It provides a new cell key clear={comma-separated list of selective cell keys} so that using \SetCell[c=2]{l, clear=preto} achieves what you want.

Full implementation with examples

```tex \documentclass{article} \usepackage{tabularray} \usepackage{xpatch} \makeatletter \ExplSyntaxOn % redefined to clear new specs "preto" and "appto" in addition \xapptocmd \__tblr_clear_spec_lists: { \__tblr_clear_one_spec_lists:n { preto } % added \__tblr_clear_one_spec_lists:n { appto } % added } {} \PatchFailed % redefined to use new spec "preto" \cs_gset_protected:Npn \__tblr_cell_preto_text:nnn #1 #2 #3 { \tl_set:Nx \l__tblr_cell_text_tl { \__tblr_spec_item:nn { preto } { [#1][#2] } } \tl_put_left:Nn \l__tblr_cell_text_tl {#3} \__tblr_spec_gput:nnV { preto } { [#1][#2] } \l__tblr_cell_text_tl } % redefined to use new spec "appto" \cs_gset_protected:Npn \__tblr_cell_appto_text:nnn #1 #2 #3 { \tl_set:Nx \l__tblr_cell_text_tl { \__tblr_spec_item:ne { appto } { [#1][#2] } } \tl_put_right:Nn \l__tblr_cell_text_tl {#3} \__tblr_spec_gput:neV { appto } { [#1][#2] } \l__tblr_cell_text_tl } \xpatchcmd \__tblr_get_cell_text_real:nn { \tl_set:Nx \l__tblr_c_tl { \__tblr_spec_item:ne { text } {[#1][#2]} } } { \tl_set:Nx \l__tblr_c_tl { \exp_not:e { \__tblr_spec_item:ne { preto } {[#1][#2]} } \__tblr_spec_item:ne { text } {[#1][#2]} \exp_not:e { \__tblr_spec_item:ne { appto } {[#1][#2]} } } } { } \PatchFailed \msg_new:nnn { tabularray } { clear-not-implemented } { Clearing ~ effect ~ of ~ cell ~ key ~ ``#1'' ~ is ~ not ~ implemented ~ (yet). } \keys_define:nn { tblr-cell-spec } { % clear = {} clear .code:n = { \clist_map_inline:nn {#1} { \cs_if_exist_use:cF { __tblr_cell_ ##1 _gclear: } { \msg_warning:nnn { tabularray } { clear-not-implemented } {##1} } } } } \cs_new_protected:Npn \__tblr_cell_preto_gclear: { \__tblr_spec_item_gclear:nn {preto} {} } \cs_new_protected:Npn \__tblr_cell_appto_gclear: { \__tblr_spec_item_gclear:nn {appto} {} } % #1 = spec item name, #2 = init value \cs_new_protected:Npn \__tblr_spec_item_gclear:nn #1#2 { \__tblr_spec_gput:nen {#1} {[\int_use:N \c@rownum][\int_use:N \c@colnum]} {#2} } \ExplSyntaxOff \makeatother \begin{document} \begin{tblr}{ vlines, colspec={Q[l, preto=\textbf{X1}, appto=\textbf{Y1}]} } \hline \SetCell{} Normal \\ \hline \SetCell{preto=\textbf{X2}} More preto \\ \SetCell{clear=preto} No preto \\ \SetCell{clear=preto, preto=\textbf{X2}} New preto \\ \hline \SetCell{appto=\textbf{Y2}} More appto \\ \SetCell{clear=appto} No appto \\ \SetCell{clear=appto, appto=\textbf{Y2}} New appto \\ \hline \SetCell{preto=\textbf{X2}, appto=\textbf{Y2}} More preto \& appto \\ \SetCell{clear={preto, appto}} No preto \& appto \\ \SetCell{ clear={preto, appto}, preto=\textbf{X2}, appto=\textbf{Y2} } New preto \& appto \\ \hline \end{tblr} \par\bigskip Original example\par \begin{tblr}{|>{Indent:}X[3]|X[8]|}%%\quad indent for non-SetCell row Alpha & Beta \\ \SetCell[c=2]{l, clear=preto}{Double width row; don't want Indent:} \\ \end{tblr} \end{document} ```

image

jonhall commented 10 months ago

Thank you ever so much for this response. It is very much appreciated.

I will work with it and come back with further suggestions, if I have any.