# two or more footnotes in a table

My question is different form the question Footnote in tabular environment because I already know how to set footnotes in tabular environments. But I don't know how to correctly use two ore more footnotes that appear together in one table. The other question is not dealing with this special issue.

I have this latex document:

\documentclass{scrbook}
\usepackage{scrlayer-scrpage}
\begin{document}
Text before the table\footnote{This is the 1st footnote}

\begin{tabular}{cl}
$k_B$ & Boltzmann constant\footnotemark $k_B = 1,380649 \cdot 10^{23} J/K$\\
$f$ & degrees of freedom\footnotemark \\
\end{tabular}
\footnotetext{named after Boltzmann}
\footnotetext{Another word for possibilities}

Text after the table\footnote{This is the last footnote}
\end{document}


I get this body, which is ok:

There are four points with footnotes, each of them has its own distinct number, as it should be. Everything is fine here.

But I get these footnotes:

As you can see, the second footnote (which is the first of two inside the table) has a wrong number. The numbers should be 1-2-3-4, but they are 1-3-3-4.

How can I get the correct numbers?

## === Reaction to an answer ===

Fran posted an answer but his solution is just a weak workaround that doesn't work properly in bigger documents with dozens of footnotes.

Suppose you are writing a book, and the table with the two footnotes is on page 580. You create the footnotes like in Fran's workaround, and 3 month later you add another text with another footnote on page 215. I want that all footnotes are correct even after adding or removing preceding footnotes.

An Example:

\documentclass{scrbook}
\usepackage{scrlayer-scrpage}
\usepackage{lipsum}
\begin{document}
\chapter*{Issue with footnotes in tables}
\lipsum[1]

% ===========================================================
% Toggle the next line
% Subsequently added text with a new footnote \footnote{additional footnote}
% ===========================================================

\lipsum[66]

Old text with a footnote\footnote{an old footnote} before the table.

\section*{Table}

\begin{tabular}{cl}
$k_B$ & Boltzmann constant\footnotemark[2]\  $k_B = 1,380649 \cdot 10^{23} J/K$\\
$f$ & degrees of freedom\footnotemark[3] \\
\end{tabular}

\footnotetext[2]{named after Boltzmann}
\footnotetext[3]{Another word for possibilities}

Text immediately after the table\footnote{immediately after the table}

\lipsum[75]

Text with a footnote\footnote{This is the last footnote}
\end{document}


This code produces this output:

But then I add some Text with another footnote before the table:

% ===========================================================
% Toggle the next line
Subsequently added text with a new footnote \footnote{additional footnote}
% ===========================================================


and I get this:

Now not only the numbers in the footnotes at the bottom of the page are wrong, but also the numbers in the table itself.

• Footnote in tabular environment might also be interesting. Mar 11, 2019 at 20:00
• Why did you mark this question as a duplicate? I clearly explained why it is different. Didn't you read the first paragraph of my question? Mar 14, 2019 at 6:46

\documentclass{scrbook}
\usepackage{scrlayer-scrpage}
\begin{document}
Text before the table\footnote{This is the 1st footnote}

\begin{tabular}{cl}
$k_B$ & Boltzmann constant\footnotemark[2]\  $k_B = 1,380649 \cdot 10^{23} J/K$\\
$f$ & degrees of freedom\footnotemark[3] \\
\end{tabular}

\footnotetext[2]{named after Boltzmann}
\footnotetext[3]{Another word for possibilities}

Text after the table\footnote{This is the last footnote}

\end{document}


Edit

Some type of automatic adjust as requested is possible making a new environment for the table notes when (1) you do not use this in floats, and (2) of course, the number of \tablefootnotemarks is the same of \tablefootnotexts for each table:

\documentclass[a6paper,twocolumn]{scrbook}
\usepackage{scrlayer-scrpage}
\usepackage{lipsum,calc,booktabs,parskip}
\newcounter{tablefootnote}
\newenvironment{foo}%
{\edef\ntnotes{\thetablefootnote}\setcounter{footnote}%
{\value{footnote}-\value{tablefootnote}}}%
{\edef\ntnotes{\thefootnote}\setcounter{tablefootnote}{0}}

\begin{document}
\raggedright
Bla \footnote{footnote 1} bla \footnote{footnote 2} Bla, \footnote{footnote 3} before the table.

\begin{tabular}{cl}\toprule
$foo$ & bah\tablefootnotemark \\
$foo$ & bah\tablefootnotemark \\
$foo$ & bah\tablefootnotemark \\
$foo$ & bah\tablefootnotemark \\\bottomrule
\end{tabular}
\begin{foo}
\tablefootnotext{footnote 4}
\tablefootnotext{footnote 5}
\tablefootnotext{footnote 6}
\tablefootnotext{footnote 7}
\end{foo}

Bla \footnote{footnote 8} bla \footnote{footnote 9} Bla, \footnote{footnote 10} after the table.

\begin{tabular}{cl}\toprule
$foo$ & bah\tablefootnotemark \\
$foo$ & bah\tablefootnotemark \\
$foo$ & bah\tablefootnotemark \\\bottomrule
\end{tabular}
\begin{foo}
\tablefootnotext{footnote 11}
\tablefootnotext{footnote 12}
\tablefootnotext{footnote 13}
\end{foo}

Bla \footnote{footnote 14} bla \footnote{footnote 15} Bla, \footnote{footnote 16} after the second table.

\begin{tabular}{cl}\toprule
$foo$ & bah\tablefootnotemark \\
$foo$ & bah\tablefootnotemark \\\bottomrule
\end{tabular}
\begin{foo}
\tablefootnotext{footnote 17}
\tablefootnotext{footnote 18}
\end{foo}

Bla \footnote{footnote 19} bla \footnote{footnote 20} Bla, \footnote{footnote 21} after the third table.

\end{document}


Footnotes work normally with longtable. See Footnotes in tables:

\documentclass{scrbook}
\usepackage{longtable}
\begin{document}
Text before the table\footnote{This is the 1st footnote}

\begin{longtable}{cl}
$k_B$ & Boltzmann constant\footnote{named after Boltzmann} $k_B = 1,380649 \cdot 10^{23} J/K$\\
$f$ & degrees of freedom\footnote{Another word for possibilities} \\
\end{longtable}

Text after the table\footnote{This is the last footnote}
\end{document}


Alternatively, if you want to stick with the tabular environment, add the footnotehyper package:

\documentclass{scrbook}
\usepackage{footnotehyper}
\begin{document}
Text before the table\footnote{This is the 1st footnote}

\begin{tabular}{cl}
$k_B$ & Boltzmann constant\footnote{named after Boltzmann} $k_B = 1,380649 \cdot 10^{23} J/K$\\
$f$ & degrees of freedom\footnote{Another word for possibilities} \\
\end{tabular}

Text after the table\footnote{This is the last footnote}
\end{document}