2

I'm trying to learn tabularray and wanted to setup some custom environments. I really like the idea of being able to move some of the layout markup outside of the actual tabular code, but there are some combinations I can't get to work.

\documentclass{article} \usepackage{xcolor} \usepackage{tabularray} \NewTblrEnviron{my-tabular} \SetTblrInner[my-tabular]{ rows={font=\sffamily}, row{1} = {bg=black!10,font=\sffamily\bfseries}, } \NewColumnType{Z}{X[font=\ttfamily]} \begin{document} \begin{tblr}{ colspec={ZX}, rows={font=\sffamily}, row{1}={bg=black!10,font=\sffamily\bfseries}, } Header left & Header right \\ item 1 left & item 1 right \\ item 2 left & item 2 right \end{tblr} \begin{my-tabular}{ colspec={ZX}, % row{1}={bg=black!10,font=\sffamily\bfseries}, } Header left & Header right \\ item 1 left & item 1 right \\ item 2 left & item 2 right \end{my-tabular} \end{document} 

The first table is what I want, but if I try to move the rows and row{1} definitions into a custom environment, the font changing commands from the colspec take priority over the one in row{1}. (Note, repeating the row{1} setting in \begin{my-tabular} works, but it feels very clumsy.)

I'm probably missing something fairly obvious, but I can't figure out a way to have the definitions from \SetTblrInner to override the colspec font changes. Any ideas how to do this in user-friendly way, leaving the code for actual table as clean as possible?

1 Answer 1

2

Default inner options set through \SetTblrInner are executed before in-document per-environment inner options, which caused the order-dependent issue OP experienced.

Here's an attempt which adds a similar \SetTblrLateInner command. With it the execution order becomes

- default inner options (\SetTblrInner[tblr]{...}) - in-document inner options (\begin{tblr}{...}) - default late inner options (\SetTblrLateInner[tblr]{...}) 

Adding support for meta option (an option as a shortcut of a list of other options) would be another solution, and it's more flexible.

\documentclass{article} \usepackage{tabularray} \usepackage{xcolor} \usepackage{xpatch} \ExplSyntaxOn \exp_args:Nc \xapptocmd { NewTblrEnviron ~ code } { \tl_new:c { l__tblr_default_ #1 _inner_late_tl } } { } { \PatchFailed } \xapptocmd \__tblr_parse_table_spec:n { % built-in tblr envs don't have _inner_late_tl \cs_if_exist:cT { l__tblr_default_ \l__tblr_env_name_tl _inner_late_tl } { \keys_set:nv { tblr } { l__tblr_default_ \l__tblr_env_name_tl _inner_late_tl } } } { } { \PatchFailed } \NewDocumentCommand \SetTblrLateInner { O{tblr} m } { \clist_map_inline:nn {#1} { \tl_put_right:cn { l__tblr_default_ ##1 _inner_late_tl } { , #2 } } \ignorespaces } \ExplSyntaxOff \NewTblrEnviron{my-tabular} % use \SetTblrLateInner \SetTblrLateInner[my-tabular]{ rows={font=\sffamily}, row{1} = {bg=black!10,font=\sffamily\bfseries}, } \NewColumnType{Z}{X[font=\ttfamily]} \begin{document} \begin{tblr}{ colspec={ZX}, rows={font=\sffamily}, row{1}={bg=black!10,font=\sffamily\bfseries}, } Header left & Header right \\ item 1 left & item 1 right \\ item 2 left & item 2 right \end{tblr} \begin{my-tabular}{ colspec={ZX}, } Header left & Header right \\ item 1 left & item 1 right \\ item 2 left & item 2 right \end{my-tabular} \end{document} 

enter image description here

1
  • Thank you! That seems to be working well, even in my more complicated real application Commented May 6, 2024 at 8:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.