4

I need to have footnotes in captions of figures and therefore use the afterpage package to keep the footnotes and the figure on the same page (also using package footnote for footnotes in figures). I need to write my PhD thesis in a style that was defined in Word, but I wanted to write in Latex. Word always puts footnotes at the bottom of the page. So basically, I'm forced to put footnotes at the bottom. Others seem to have the same problem (other question, accepted answer puts footnote on bottom of page, but is manual; also for tables that might float and floats in general, where I found the idea with afterpage; also in other places on the web), so I though I might share my progress made so far and get input from others on the issue.

When using floats in an afterpage environment, the ordering of the footnotes at the bottom gets mangled up in some parts of the document. I managed to fix the ordering of the footnotes at the bottom with a dirty hack (see below), but the footnote number of the figure is not always the first footnote number appearing on the page. So I now have basically two questions:

  1. What does my dirty hack do? I just tried some things and somehow it worked, now I'd like to understand why and whether it might have effects on other parts of the document.
  2. How can I get the correct footnote number, i.e. the lowest footnote number on that page, for the footnote of the caption?

My dirty hack (using \patchcmd from etoolbox):

\usepackage{etoolbox}

\makeatletter
\tracingpatches
\patchcmd{\AP@savetop}{\global\setbox\AP@footins\box\footins}{}{}{}
\patchcmd{\AP@@}{\insert\footins{\unvbox\AP@footins}\fi}{\setbox\footins\vbox{\unvbox\AP@footins}\fi}{}{}
\makeatother

What I get without my dirty hack:

  • Footnotes on same page as figure
  • Footnotes order not correct
  • Footnote number of caption not first number on page

What I get without my dirty hack

What I get with my dirty hack

  • Footnotes on same page as figure
  • Footnotes order correct
  • Footnote number of caption not first number on page

What I get with my dirty hack

What I want

  • Footnotes on same page as figure
  • Footnotes order correct
  • Footnote number of caption first number on page

MWE:

\documentclass[12pt,a4paper,twoside,openany,fleqn]{book}

\usepackage{afterpage}
\usepackage[ngerman]{babel}
\usepackage{lipsum}
\usepackage{footnote}
\makesavenoteenv{figure}

\begin{document}
\chapter{First Chapter}

\lipsum[1]\footnote{Footnote}
\afterpage{
    \begin{figure}[htp]
        \fbox{Hello World}
        \caption[test]{test\protect\footnote{Test}}
    \end{figure}
}
\lipsum[1]\footnote{Footnote}
\lipsum[1]\footnote{Footnote}
\lipsum[1]\footnote{Footnote}
\afterpage{
    \begin{figure}[htp]
        \fbox{Hello World}
        \caption[test]{test\protect\footnote{Test}}
    \end{figure}
}
\lipsum[1]\footnote{Footnote}
\lipsum[1]\footnote{Footnote}

\end{document}

Edit1: Second MWE without afterpage, where footnote is kept on different page. Adding afterpage around the figures moves the footnote to the correct page:

\documentclass[12pt,a4paper,twoside,openany,fleqn]{book}

\usepackage[ngerman]{babel}
\usepackage{lipsum}
\usepackage{footnote}
\makesavenoteenv{figure}

\begin{document}
\chapter{First Chapter}

\lipsum[1]\footnote{Footnote}

    \begin{figure}[tp]
        \begin{minipage}[t][0.4\textheight][t]{0.6\textwidth}
                \end{minipage}
        \caption[test]{test\protect\footnote{Test}}
    \end{figure}

\lipsum[1]\footnote{Footnote}
\lipsum[1]\footnote{Footnote}
\lipsum[1]\footnote{Footnote}

    \begin{figure}[tp]
        \begin{minipage}[t][0.4\textheight][t]{0.6\textwidth}
    \end{minipage}
    \caption[test]{test\protect\footnote{Test}}
    \end{figure}

\lipsum[1]\footnote{Footnote}
\lipsum[1]\footnote{Footnote}

\end{document}

Footnote on first page Figure floats to second page, footnote does not

ThomasD
  • 111
  • I would not change the .sty directly but do that with a patch in your document. But at first. Why do you need afterpage? If you just kick all the afterpage stuff out, it works just as you desire. With help of \protect, the footnotes will always be correct. Well, I believe. If not, take a look on \footnotemark and \footnotetext! – LaRiFaRi Jul 30 '14 at 07:29
  • 1
    Don't use footnotes with captions. Sett the fotenote inside the object, where it belongs. – Johannes_B Jul 30 '14 at 07:32
  • @LaRiFaRi: if you change the contents of the figure from
    \fbox{Hello World}
    to
    \begin{minipage}[t][0.4\textheight][t]{0.6\textwidth}\end{minipage}
    , you will see that the figure will be moved to the next page, the footnote is not. That's why I need afterpage. I tried using footnotemark/-text, but I didn't get better results. I don't want to manually move the footnote where I want it to appear.
    – ThomasD Jul 30 '14 at 08:06
  • I am having a bad day as you can see above: Annotations to a graphic or table are typeset inside the figure environment. That is the place where does annotations belong to. The thing you are trying to achieve is not only bad typography, but also error prone. – Johannes_B Jul 30 '14 at 08:09
  • @Johannes_B: thanks for the comment. So is there a way of achiving what I want without putting the footnote into the caption? For my thesis I need to have footnotes at the bottom of the page, not somewhere else, e.g. in a minipage directly beneath the figure. Putting the footnote inside the figure environment does not work, as the position of the footnotemark is not correct. – ThomasD Jul 30 '14 at 08:14
  • @ThomasD You should show us such an example. With minipage and footnote on other side. This is not the normal behaviour and you should work that out first. – LaRiFaRi Jul 30 '14 at 08:22
  • @LaRiFaRi: Sorry, first time on stackexchange. I edited my post to show another MWE without afterpage that shows the behavior I'm trying to avoid: the footnote is on the page before the figure. I'm only using the minipage environment to simulate a figure of some size. Maybe there is a better command to simulate a figure? – ThomasD Jul 30 '14 at 08:32
  • @ThomasD The MWE can be reduced to \documentclass{book} \usepackage[demo]{graphicx}\begin{document}\chapter{First Chapter}\begin{figure}[tp]\includegraphics{whatever.png} \caption[test]{test\protect\footnotemark}\end{figure} \footnotetext{Test}\end{document}. Can't help you, sorry. Remove the [tp] would be my advice but I guess you want to have it that way. I always recommend to let the floats float. Much more beautiful. – LaRiFaRi Jul 30 '14 at 09:26
  • @LaRiFaRi: Thank you for your help. Still, removing [tp] does not solve the problem of the footnote beeing on the wrong page if the figure floats to the next page. Maybe someone else has an idea. – ThomasD Jul 30 '14 at 09:34
  • 2
    @ThomasD why do you want the footnote to be on the bottom of the page rather than at the bottom of the float? LaTeX does not support that essentially because no one should want it. – David Carlisle Jul 30 '14 at 10:13
  • Here are two ways to get a footnote in the table (or figure) itself, and not at the bottom of the page: http://tex.stackexchange.com/questions/10181/using-footnote-in-a-figures-caption/99289#99289 and http://tex.stackexchange.com/questions/10181/using-footnote-in-a-figures-caption/99293#99293 – Steven B. Segletes Jul 30 '14 at 11:14
  • One should also mention package threeparttable. – Johannes_B Jul 30 '14 at 11:42
  • @DavidCarlisle: Hey David, thanks for commenting. Maybe you remember my email about this issue. I edited the question to reflect why I (and obviously others) have this problem. But I bet you are right, Latex does not seem to support my wish (although at least partly solved with my hack) since it strongly refuses to accept my attempts to put the footnotes at the bottom with the "Word-like" numbering. Anyway, I HAVE to want those changes due to the template I have to comply with, so I still would like to try and get an answer.

    I also saw the 'threeparttable', but it doesn't solve my problem.

    – ThomasD Jul 30 '14 at 15:12
  • How about hyperref, does your hack give you any problems? – yannisl Jul 30 '14 at 15:30
  • @YiannisLazarides: Just checked: added hyperref to both MWE and hyperref did it's work. Clicking on the footnotemarks near the caption stays on the same page when using afterpage, but switches to the previous page when footnote is not on the same page. No errors/warnings in Latex. However, in my thesis document I get warnings like this: pdflatex> pdfTeX warning (dest): name{Hfootnote.1} has been referenced but does not exist, replaced by a fixed one. I'm not sure, but I think the problems lies in other parts of the doc. Also, when adding two footnotes, the second footnote ref works. – ThomasD Jul 30 '14 at 15:50

2 Answers2

7

There is no way to do this with floating figures without rewriting half of latex: the caption (including any footnote marks) is set at the point of the figure environment and a floating figure can float past footnotes, thus getting the footnote numbers out of order.

If you really want this output style (I can see no good reason for it, a float is by design a distinct object not in the main flow of text on the page, and so having its footnotes in the page just seems wrong) then you need to use non floating figures.

You can use float package \begin{figure}[H] or or caption or capt-of package \captionof{figure}{...} then the figure is not a floating object but fixed in the page, and you can then use \footnotemark in the caption and \footnotetext immediately after the \end{figure} and they will come on the same page.

David Carlisle
  • 757,742
1

I was able to handle this issue using \clearpage. First, I grouped my figure and the footnote by using \afterpage{...} and \protect\footnotemark within the figure's caption and \footnotetext after the figure but within \afterpage{...}. Immediately after this grouping, I put \clearpage. This created the output with the correct footnote order and the correct numbering order easily. See also this post: Figures enumeration in wrong order

guest
  • 11