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.

7
  • See here: tex.stackexchange.com/a/327385/230596
    – Mafsi
    May 24, 2022 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, 2022 at 17:43
  • Does this so,Union help? tex.stackexchange.com/questions/636963/…
    – Celdor
    May 24, 2022 at 17:55
  • 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. github.com/lvjr/tabularray/issues/179. May 24, 2022 at 18:52
  • 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. May 24, 2022 at 19:17

3 Answers 3

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

4
  • 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, 2022 at 6:46
  • 1
    @Miyase You can find some examples of functional library from github.com/lvjr/tabularray/issues/81
    – L.J.R.
    May 25, 2022 at 6: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 2, 2022 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 9, 2023 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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .