GeneralPut footnotes at end of longtable

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
nunolf
Posts: 14
Joined: Wed Jul 18, 2007 1:41 pm

Put footnotes at end of longtable

Post by nunolf »

Hi *

Goal: put the footnotes at the end of a longtable, NOT at the page end

Yes ,how know this is tricky question. I read all stuff I could find out on the net and on books I have here on the lab, but I can´t seem to put this working.

For small tables, there are a couple of ways to put footnotes at the end of a table (e.g. put table inside a minipage, threparttable package). For long tables, I read something about putting the footnotes in a multicolumn row, at the end of the table. Do you guys have an example of how to do this? Bellow, an example of a longtable with footnotes on the headins and on the body.

Cheers,
Nuno

Code: Select all

\documentclass{book}

\usepackage{booktabs}
\usepackage{longtable}

\begin{document}

% Here's a long table
\begin{center}
% Change the footnote style to symbols
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\begin{longtable}{ccccccc}
\caption[Optional table caption]{Main caption\footnotemark[1]}\\

% This is the header for the first page of the table...
\toprule
\multicolumn{4}{c}{Interacting Residues\footnotemark[2]} &	   &	    &	   \\
Residue	& Chain & Residue & Chain	     & M-M  & M-S  & S-S\\
\midrule
\endfirsthead

% This is the header for the remaining page(s) of the table...
%\multicolumn{7}{c}{{\tablename} \thetable{} -- Continued} \\
\caption[]{(continued)}\\
\toprule
\multicolumn{4}{c}{Interacting Residues\footnotemark[2]} &	   &	    &	   \\
Residue	& Chain & Residue & Chain	     & M-M  & M-S  & S-S\\
\midrule
\endhead

% This is the footer for all pages except the last page of the table...
\midrule
\multicolumn{7}{l}{{Continued on Next Page\ldots}} \\
\endfoot

% This is the footer for the last page of the table...
\bottomrule
\endlastfoot

% Data starts here:
\multicolumn{7}{l}{A. Common contacts\footnotemark[3]}\\
Glu 92	& A	& Val 94	& B	&	10/9	&		&		\\
Val 94	& A	& Glu 92	& B	&	10/10	&		&		\\
% lots of other rows bellow
\end{longtable}

% Footnote text
\footnotetext[1]{First footnote on the caption}
\footnotetext[2]{Second footnote on the heading}
\footnotetext[3]{Third footnote inside table's body}
\end{center}

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Put footnotes at end of longtable

Post by localghost »

Embed your longtable environment in a minipage environment and adapt its width to that of the table. So the footnotes will be aligned with the bottom left corner of the table. Note that the footnotemarks will not be numbers, but small characters. The counter for footnotes in minipages is mpfootnote. You may customize them with the footmisc package.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
nunolf
Posts: 14
Joined: Wed Jul 18, 2007 1:41 pm

Re: logtable - footnotes

Post by nunolf »

Hi ghost(local)

As I said in the beginning of my post, for tables that do not cross pages, a minipage could be a solution. But for tables that do cross pages, thus the need for longtable, you cannot use the minipage concept, because it was designed within that scope.

At least, that's what I read and from my own experience, though I'm a LaTeX 2 months newbye.

Many thanks.
Nuno
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Re: logtable - footnotes

Post by localghost »

OK, my fault. Didn't read your post careful enough. So, at this point i'm out.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Put footnotes at end of longtable

Post by gmedina »

This is a possible solution:

Code: Select all

\documentclass{book}

\usepackage{booktabs}
\usepackage{longtable}
%define your footnote marks
\newcommand{\myfnmark}[1]{\mbox{\textsuperscript{\normalfont #1}}}
%redefine the way the footnotes are shown, to use your footnote marks
\makeatletter
\renewcommand\@makefntext[1]%
  {\noindent\makebox[1.8em][r]{\myfnmark}#1} 
\makeatother

\begin{document}

% Here's a long table
\begin{center}
% Change the footnote style to symbols
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\begin{longtable}{ccccccc}
\caption[Optional table caption]{Main caption\footnotemark[1]}\\

% This is the header for the first page of the table...
\toprule
\multicolumn{4}{c}{Interacting Residues\footnotemark[2]} &      &       &      \\
Residue   & Chain & Residue & Chain        & M-M  & M-S  & S-S\\
\midrule
\endfirsthead

% This is the header for the remaining page(s) of the table...
%\multicolumn{7}{c}{{\tablename} \thetable{} -- Continued} \\
\caption[]{(continued)}\\
\toprule
\multicolumn{4}{c}{Interacting Residues\footnotemark[2]} &      &       &      \\
Residue   & Chain & Residue & Chain        & M-M  & M-S  & S-S\\
\midrule
\endhead

% This is the footer for all pages except the last page of the table...
\midrule
\multicolumn{7}{l}{{Continued on Next Page\ldots}} \\
\endfoot

% This is the footer for the last page of the table...
\bottomrule
\endlastfoot

% Data starts here:
\multicolumn{7}{l}{A. Common contacts\footnotemark[3]}\\
Glu 92   & A   & Val 94   & B   &   10/9   &      &      \\
Val 94   & A   & Glu 92   & B   &   10/10   &      &      \\
% lots of other rows bellow
\end{longtable}

% Footnote text
\begin{minipage}{.5\linewidth}
%do not draw the footnoterule
\renewcommand{\footnoterule}{}
\footnotetext[1]{\myfnmark{$\ast$} First footnote on the caption}
\footnotetext[2]{\myfnmark{$\dagger$} Second footnote on the heading}
\footnotetext[3]{\myfnmark{$\ddagger$} Third footnote inside table's body}
\end{minipage}
\end{center}

\end{document}
However, every time you use the \footnote command you will have to explicitly indicate the footnotemark to be used.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
nunolf
Posts: 14
Joined: Wed Jul 18, 2007 1:41 pm

Re: logtable - footnotes

Post by nunolf »

Hi medina(g)

I understood your idea. Put the footnotes on a separate minipage. That's a nice suggestion, but, you cannot pass the footnote marks written outside the minipage environment into it, can you?

At the end, with some tweaking on the latex stuff inside the minip env, your idea works just perfectly. Many thanks.
N.
cmoreno
Posts: 2
Joined: Fri Jan 21, 2022 5:00 am

Put footnotes at end of longtable

Post by cmoreno »

Hi gmedina,
I applied your proposed solution to one of my tables and it works. However, for each individual footnote added, I get the following 7 errors no matter what is written in the 'footnote':
Missing } inserted.
Missing $ inserted.
Extra }, or forgotten \endgroup.
Extra }, or forgotten $.
Extra }, or forgotten $.
Extra }, or forgotten $.
Illegal unit of measure (pt inserted).

The line higlighted for these errors is the one where the footnote was written. In your example, this would be line 59, 60 and 61. Each of them will have the errors mentioned above.
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Put footnotes at end of longtable

Post by rais »

Hi cmoreno,
the messages are caused by gmedina's redefinition of \@makefntext:

Code: Select all

\makeatletter
\renewcommand\@makefntext[1]%
  {\noindent\makebox[1.8em][r]{\myfnmark}#1} 
\makeatother
where \myfnmark is defined to get one parameter of its own, which leads to \myfnmark grabbing the closing brace---the next token---as its parameter which in turn leads to the braces being unbalanced. A redefinition like

Code: Select all

\makeatletter
\renewcommand\@makefntext[1]%
  {\noindent\makebox[1.8em][r]{\myfnmark{#1}}}
\makeatother
might remedy that, though that may not have been intended...and then I started thinking about this by now almost fifteen-year old thread...shouldn't it be possible to `pass on the footnote marks to the footnote texts' somehow?

Code: Select all

\documentclass{book}

\usepackage{booktabs}
\usepackage{longtable}

\newenvironment{footnotecollector}[1]{%
  \begin{minipage}{#1}%
  \renewcommand{\thempfootnote}{\fnsymbol{mpfootnote}}%
  \providecommand\nextfootnotetext[1]{%
    \stepcounter{mpfootnote}%
    \footnotetext{##1}%
  }%
}{%
% At the end of `footnotecollector', check if there's any discrepancy between marks and texts:
  \ifnum\value{footnote}>\value{mpfootnote}\relax
    \typeout{+!+ More footnote marks (\arabic{footnote}) given than footnote texts (\arabic{mpfootnote})!}%
  \else
    \ifnum\value{footnote}<\value{mpfootnote}\relax
      \typeout{+!+ More footnote texts (\arabic{mpfootnote}) given than footnote marks (\arabic{footnote}) encountered!}%
    \fi
  \fi
  \end{minipage}%
}
  
\begin{document}

% Here's a long table
\begin{center}
% Change the footnote style to symbols
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\begin{longtable}{ccccccc}
\caption[Optional table caption]{Main caption\footnotemark}\\

% This is the header for the first page of the table...
\toprule
\multicolumn{4}{c}{Interacting Residues\footnotemark} &      &       &      \\
Residue   & Chain & Residue & Chain        & M-M  & M-S  & S-S\\
\midrule
\endfirsthead

% This is the header for the remaining page(s) of the table...
\caption[]{(continued)}\\
\toprule
\multicolumn{4}{c}{Interacting Residues} &      &       &      \\
Residue   & Chain & Residue & Chain        & M-M  & M-S  & S-S\\
\midrule
\endhead

% This is the footer for all pages except the last page of the table...
\midrule
\multicolumn{7}{l}{{Continued on Next Page\ldots}} \\
\endfoot

% This is the footer for the last page of the table...
\bottomrule
\endlastfoot

% Data starts here:
\multicolumn{7}{l}{A. Common contacts\footnotemark}\\
Glu 92   & A   & Val 94   & B   &   10/9   &      &      \\
Val 94   & A   & Glu 92\footnotemark   & B   &   10/10   &      &      \\
% lots of other rows bellow
\end{longtable}

% Footnote text
\begin{footnotecollector}{.5\linewidth}
%do not draw the footnoterule
\renewcommand{\footnoterule}{}%
\nextfootnotetext{First footnote on the caption}
\nextfootnotetext{Second footnote on the heading}
\nextfootnotetext{Third footnote inside table's body}
\nextfootnotetext{Another footnote inside table's body}
\end{footnotecollector}
\end{center}
\end{document}
For any consecutive longtable/footnotecollector pairs you may wish to reset the footnote counter, though (\setcounter{footnote}{0} just before the next longtable containing footnotes to be collected)

KR
Rainer
Post Reply