2

I have a document with several tables where the content is created dynamically. Therefore, I use the evaluate functionality of tabularray.

Along with that, on some of those table, I would need to also dynamically define if I have to add a footnote to that table or not. And here is my problem.

While creating the content, I have conditions defining if I have to add a specific footnote, but then, I end up with the

Test.tex: error: 67: Package tabularray Error: Unknown outer key name '\MyTableFootNote'. \end

Here is a small test with just the command manually created, so the error can be checked:

\documentclass[% 10pt,% paper=a4,% twoside=true,% openany,% ]{scrbook}% % \usepackage{tabularray}% \UseTblrLibrary{diagbox, functional, varwidth}% % \NewTblrTheme{MyTable}{% \SetTblrStyle{caption-tag}{red2}% \SetTblrStyle{caption-sep}{red2}% \SetTblrStyle{head}{font=\bfseries\itshape}% \SetTblrStyle{foot}{\itshape, fg=blue2}% }% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document}% \begin{longtblr}% [% theme = MyTable,% label = {tab:TestTableA},% caption = {Test table},% note{$\dagger$} = {This is my remarks.}% ] {% colspec = X|X|X,% width = 1.0\linewidth,% measure = vbox,% rowhead = 1,% rowfoot = 0,% row{1} = {halign=center, font=\bfseries, c},% }% \hline% Test & Test & Test \\ \hline% Test & Line & \# 1 \\ \hline% Test & Line & \# 2 \\ \hline% Test & Line & \# 3 \\ \hline% \end{longtblr}% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \NewDocumentCommand\MyTableFootNote{}{note{$\dagger$} = {This is my remarks.}}% % \def\MyTableFootNote{note{a} = {This is my remarks.}}% \begin{longtblr}% [% theme = MyTable,% label = {tab:TestTableB},% caption = {Test table with the conditional foot note},% \MyTableFootNote% ] {% colspec = X|X|X,% width = 1.0\linewidth,% measure = vbox,% rowhead = 1,% rowfoot = 0,% row{1} = {halign=center, font=\bfseries, c},% }% \hline% Test & Test & Test \\ \hline% Test & Line & \# 1 \\ \hline% Test & Line & \# 2 \\ \hline% Test & Line & \# 3 \\ \hline% \end{longtblr}% % \end{document}% 

Thanks in advance for all the help,

4
  • this wouldn't work with any key-value interface I'm aware of. you need to expand whatever so tabularray sees the key = value when parsing. so you can't use \NewDocumentCommand. you can use \newcommand or \NewExpandableDocumentCommand if the stuff is expandable and can be handled safely. what kind of content might be in the footnote? do you control how that is generated? could it be treated as a string, say? Commented Oct 31 at 7:28
  • Yes, I do control the generation. I've tried the \newcommand & \NewExpandableDocumentCommand, but both of them get me the same error. Commented Oct 31 at 9:32
  • I didn't mean those would be sufficient. It was more a question of whether you are asking for something possible. you can see the explanation in tabularray's manual for information about ways to pre-expand macros. Commented Oct 31 at 16:47
  • but jlab's approach is the more natural one, imho. Commented Oct 31 at 16:52

1 Answer 1

4

As tabularray uses a key-value interface, you need to use keys for that. You can define a new key (see the manual, section 7.1, Experimental public key paths)

\DeclareKeys[tabularray/table/outer]{ my-dynamic-settings .meta:n = {note{a} = {This is my remarks.}} } 

and use it in the outer setting place

\begin{longtblr}% [% theme = MyTable, label = {tab:TestTableB}, caption = {Test table with the conditional foot note}, my-dynamic-settings ] 

When you need to change the setting, you only have to redefine the key

\DeclareKeys[tabularray/table/outer]{ my-dynamic-settings .meta:n = {note{b} = {This is another remarks.}} } 

Example:

\documentclass{scrbook} \usepackage{tabularray} \DeclareKeys[tabularray/table/outer]{ my-dynamic-settings .meta:n = {} } \NewDocumentCommand{\testtable} { } {% \begin{longtblr} [ my-dynamic-settings ] { XX } \hline Test & Test \\ Test & Line \\ Test & Line \\ \hline \end{longtblr} } \begin{document} \testtable \DeclareKeys[tabularray/table/outer]{ my-dynamic-settings .meta:n = {note{a} = {This is my remarks.}} } \testtable \DeclareKeys[tabularray/table/outer]{ my-dynamic-settings .meta:n = { note{a} = {This is my note a.}, note{b} = {This is my note b.}, remark{$\dagger$} = {This is my remarks.}, caption = {Test table with the conditional foot note},% } } \testtable \end{document} 

Example

1
  • 1
    Thanks @jlab, it works like a charm... Commented Nov 3 at 5:23

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.