9

I'm almost done switching to tabularray but have just one final problem to solve.

Using \footnote inside tblr doesn't work properly, but it's a known problem with most (all?) table-like environments. After a bit of research, I tried this:

\documentclass{article}
\usepackage{tabularray}
\usepackage{footnote}
\makesavenoteenv{tblr}
\UseTblrLibrary{counter}

\begin{document}

\begin{tblr}{colspec={ll}} a line & a text\footnote{with a note} in the middle\ another line & another text\footnote{with another note} in the middle \end{tblr}

\end{document}

Thanks to \UseTblrLibrary{counter}, the footnotes are numbered correctly inside the table, but the footnotes themselves are badly handled and appear multiple times:

Result1

Second try, I used \TblrNote provided by tabularray:

\documentclass{article}
\usepackage{tabularray}

\begin{document}

\begin{longtblr}[ note{1}={with a note}, note{2}={with another note} ]{colspec={ll}} a line & a text\TblrNote{1} in the middle\ another line & another text\TblrNote{2} in the middle \end{longtblr}

\end{document}

which yields this:

Result2

But this solution isn't satisfactory for several reasons:

  • The footnote numbers in the table don't handle spaces after them correctly, as shown in the picture above.
  • I'd have to number footnotes manually, which is a big no-no in LaTeX.
  • The footnotes themselves aren't rendered like normal footnotes: wrong font size, no horizontal rule above them, and their numbers ignore previously existing footnotes on other pages.

Is there a clean way to get real footnotes with tabularray? Thanks for your attention.

Miyase
  • 2,544
  • 2
  • 12
  • 26
  • See here: https://tex.stackexchange.com/a/327385/230596 – Mafsi May 24 '22 at 17:41
  • Thanks for the comment, but unless I'm mistaken this solution doesn't use tabularray. As I explained at the beginning of my post, the very point is to completely switch to this package. Also, it seems to create notes attached to the table instead of the page. – Miyase May 24 '22 at 17:43
  • Does this so,Union help? https://tex.stackexchange.com/questions/636963/footnotes-in-table-not-numbered-properly – Celdor May 24 '22 at 17:55
  • Yes, I did see this page when I searched. The problem is that this solution is mostly a "quick'n' dirty hack", requiring manual tinkering each time I have a footnote in a table. If I keep using tabular, I just load the footnote package and everything is handled cleanly and automatically. I'm wondering if I can get to this point with tabularray. – Miyase May 24 '22 at 18:05
  • 2
    tabularray processes the body more than once but currently misses a suitable interface to distinguish (and hook into) the measuring phase from the typesetting phase. https://github.com/lvjr/tabularray/issues/179. – Ulrike Fischer May 24 '22 at 18:52
  • @UlrikeFischer Does this mean that there is no clean way to handle footnotes at this time? I'm just curious, if it's the case, I'll just revert to good ol' tabular when I need footnotes. For the huge majority of my usecases, tabularray passed with flying colors. – Miyase May 24 '22 at 19:02
  • 1
    I don't think so. Also imho for such simple tabulars as in your example using tabularray is overdoing. As you can see from the footnotes (or if you remove the counter library) it typesets some parts quite often. This can slow down the compilation noticably. – Ulrike Fischer May 24 '22 at 19:17

3 Answers3

4

You don't need to update your documents or TeX distribution if your documents work well. In fact, most of my documents are still using traditional tabular environment, compiled on a 10 year old MiKTeX distribution. :-)


Anyway, here is a possible solution. With the newly added functional library you can split each footnote into \footnotemark and \footnotetext, then add footnote text after the table with some hook. Maybe it is not perfect, but at least it works.

\documentclass{article}
\usepackage[a6paper]{geometry}

\usepackage{tabularray} \UseTblrLibrary{counter} \UseTblrLibrary{functional}

\makeatletter \IgnoreSpacesOn \tlNew \gFootNoteTl \intNew \gFootNoteInt \prgNewFunction \footNote {m} { \tlPutRight \gFootNoteTl { \stepcounter{footnote} \footnotetext{#1} } \prgReturn {\footnotemark{}} } \AddToHook{env/tblr/before}{ \intSetEq \gFootNoteInt \c@footnote \tlClear \gFootNoteTl } \AddToHook{env/tblr/after}{ \intSetEq \c@footnote \gFootNoteInt \tlUse \gFootNoteTl } \IgnoreSpacesOff \makeatother

\begin{document}

Some note\footnote{some note} before.

\bigskip

\begin{tblr}[evaluate=\footNote]{colspec={ll},hlines} a line & a text\footNote{with a note} in the middle\ another line & another text\footNote{with another note} in the middle \end{tblr}

\bigskip

\begin{tblr}[evaluate=\footNote]{colspec={ll},hlines} a line & a text\footNote{with a note} in the middle\ another line & another text\footNote{with another note} in the middle \end{tblr}

\bigskip

Another note\footnote{another note} after.

\end{document}

enter image description here

L.J.R.
  • 10,932
  • Thank you. I know I don't have to update everything, but I like tabularrray syntax better, and when I find a good replacement for a tool, I usually want to get rid of the old one as fast as possible. Call if irrational. As for your answer, I've never played with functional, this might be a good starting point. – Miyase May 25 '22 at 06:46
  • 1
    @Miyase You can find some examples of functional library from https://github.com/lvjr/tabularray/issues/81 – L.J.R. May 25 '22 at 06:53
  • Well, the "only" issue with tabularray is that it compiles kind of slowly -- but (I assume the bottleneck is with the boxing instead of the token-processing part, didn't actually measure) it's not a built-in like halign so can't compete... – user202729 Jun 02 '22 at 17:17
  • The \footnotetext command in the function does not seem to work, i.e., it does not produce any footnote. The hooks can be seen to be evaluated. My guess is that the \footnotetext command needs to be invoked outside environments, including tabularray ones. This is speaking of tabularray 2022-06-01 v2022B. – 54690 Dec 09 '23 at 13:46
3

I want to add another answer to make some explanations of the table notes in talltblr or longtblr in tabularray package.

The \TblrNote command is similar to \tnote in threeparttable package and \tnotex in threeparttablex package. Table notes are different from footnotes. They are put after the tables. So it is better not to mix them with footnotes. Many users choose to use alphabet values (a,b,c,...) as note marks.

You need to specify the note mark in \TblrNote command, but there is an advantage that you can give the same note mark in different \TblrNote (see the example below). Some users think this is useful.

Also by default \TblrNote command \rlap the note mark (It is also the default setup of \tnote and \tnotex commands in threeparttable and \threeparttablex packages). One of the reasons is that it makes siunitx numbers align well (see the example below).

You can change the default setting by redefine \TblrOverlap command.

\renewcommand\TblrOverlap[1]{#1}

The above code line removes the default \rlap setting.


Now here is a complete example showing the usages of \TblrNote command:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx}

\begin{document}

\begin{talltblr}[ caption = {First Table}, note{a} = {with a note}, note{b} = {with another note} ]{ colspec = {S[table-format=3.2]S[table-format=3.2]}, row{1} = {guard} } \toprule Some Head Text & Some Head Text \ \midrule 111.22 & 111.22\TblrNote{a} \ 222.33\TblrNote{b} & 222.33 \ 333.44 & 333.44\TblrNote{b} \ \bottomrule \end{talltblr}

\vspace{2em}

\renewcommand\TblrOverlap[1]{#1}

\begin{talltblr}[ caption = {Second Table}, note{a} = {with a note}, note{b} = {with another note} ]{colspec={ll}} \hline a line & a text\TblrNote{a} in the middle \ another line & another text\TblrNote{b} in the middle \ \hline \end{talltblr}

\end{document}

enter image description here

L.J.R.
  • 10,932
0

This is just a tiny modification of the L.J.R. answer, that works with longtblr, i.e.:

\documentclass{article}
\usepackage{geometry}

\usepackage{tabularray} \UseTblrLibrary{counter} \UseTblrLibrary{functional}

\makeatletter \IgnoreSpacesOn \tlNew \gFootNoteTl \intNew \gFootNoteInt \prgNewFunction \footNote {m} { \tlPutRight \gFootNoteTl { \stepcounter{footnote} \footnotetext{#1} } \prgReturn {\footnotemark{}} } \AddToHook{env/longtblr/before}{ \intSetEq \gFootNoteInt \c@footnote \tlClear \gFootNoteTl } \AddToHook{env/longtblr/after}{ \intSetEq \c@footnote \gFootNoteInt \tlUse \gFootNoteTl } \IgnoreSpacesOff \makeatother

\begin{document}

Some note\footnote{some note} before.

\bigskip

\begin{longtblr}[evaluate=\footNote]{colspec={ll},hlines} a line & a text\footNote{with a note} in the middle\ another line & another text\footNote{with another note} in the middle \end{longtblr}

\bigskip

Another note\footnote{another note} after.

\end{document}

enter image description here

Ommo
  • 835