# Footnote appearing on the next page when there's too much space on a page

I am trying to get the footnote to appear on the same page (1st) as the reference of it in the main text but it appears on the next page (2nd) instead.

The closest to my problem I can find is Footnote appears on next page. Why? but my problem does not seem to be too little space on the page. In fact, when I add something to the paragraph to make it longer and reduce the space at the bottom of the page, the footnote can then appear on the 1st page with pretty much nothing else changed about the layout.

The reduced source code is the following,

\documentclass[letter]{article}

\usepackage{setspace}

\begin{document}

\small \rm
\setstretch{2.0}

a aj jfskdj pojsdf jasdfj jjiaosdjf jaisdojf ajsidfj oaijds fsojijf sd,

\vspace{11cm}

a aj jfskdj pojsdf jasdfj jjiaosdjf jaisdojf ajsid\footnote{fasu tuthwery ;xncdnbcd},
fpoiajsdfpoiajdskajsdpof  fiosd f asd faijdf a df a jfpo oiaf pa pfoija
fpoiajsdfpoiajdskajsdpof  fiosd f asd faijdf a df a jfpo oiaf pa pfoija
fpoiajsdfpoiajdskajsdpof  fiosd f asd faijdf a df a jfpo oiaf pa pfoija
fpoiajsdfpoiajdskajsdpof  fiosd f asd faijdf a df a jfpo oiaf pa pfoija
% Uncomment the following to fix the problem...
% fpoiajsdfpoiajdskajsdpof  fiosd f asd faijdf a df a jfpo oiaf pa pfoija

\begin{figure}
\centering
\caption{
JHLHL Jlkjaklsdf jalksjdf kja;d fa;skldjf ;aksdjf japisodf
fpoiajsdfpoiajdskajsdpof  fiosd f asd faijdf a df a jfpo oiaf pa pfoija
pdo fpaisodf aosdjf ia psfj aspoidjaposifjpaiod fpiaos fpais pfoa sdpoif sdf}
\end{figure}
fpoiajsdfpoiajdskajsdpof  fiosd f asd faijdf a df a jfpo oiaf pa pfoija
fpoiajsdfpoiajdskajsdpof  fiosd f asd faijdf a df a jfpo oiaf pa pfoija

\end{document}


and I can reproduce this issue using either pdflatex or xelatex.

This comes out of a 200+ pages document so I would really like a robust and automatic solution so that I don't need to manually review the document everytime there's a change... I would also like to understand why this is happening. It really seems that the footnote can fit on the first page without any problems. Any notes about the internal or how to debug something like this will also be appreciated.

Note: This issue is sensitive to the space available at the bottom of the first page so it's fairly sensitive to how much space the content on the first page takes. I'm not really looking for advance on how to change that to avoid hitting this issue. If you made any change to the document that causes the issue to go away, try changing the vspace value a little to see if it merely stops triggering the issue due to the chang in the vertical position. The text before the section header should be on the first page with just enough room at the bottom of the page whereas the figure and the section should be on the second page. I'd like the footnote to be on the first page but it appears on the second one even when there's clearly enough space on the first one.

I'm using TeX Live 2020.57066 on Arch Linux. Also reproduced on overleaf using pdfLatex and texlive version 2020 (currently the default).

• Double space is required for this document. I'd also like to understand why it get confused and I would really like an automatic solution. This is part of a 200 pages document and I don't really want to review it page by page. – yuyichao Jan 5 at 14:01
• I suspect the issue has to do with the float (figure). Are you able to make a MWE without any floats? – Willie Wong Jan 5 at 15:03
• A couple comments: (a) if you swap the ordering of the text after the new section and the float, then the problem goes away with no obvious changes to lengths; so I really think this is a float issue. (b) a similar question was previously posted tex.stackexchange.com/questions/6756/… and the suggestion there is that the bigfoot package somehow fixes this as a side effect. You can try that. – Willie Wong Jan 5 at 15:14
• This reminds me terribly of github.com/latex3/latex2e/issues/399 – cgnieder Jan 5 at 15:39
• @cgnieder: I think you hit the nail on the head! The comments by u-fischer is exactly a duplicate of this, and for this particular case a solution was found by MIttelbach. I will summarize that in an answer. – Willie Wong Jan 5 at 15:54

This is an issue with how the TeX output routine works in the presence of floats. The exact same issue has been reported to the LaTeX team here as part of a larger issue that involves also other parts of TeX. I'll let Frank Mittelbach explain what is happening:

Whenever LaTeX encounters a float it calls on the output routine [N.B. this is "OR" below] to settle its placement. After that the OR returns the page material back to the main vertical list but there will be one difference:

• before the call to the OR the footnotes are individually located next to the place they are encountered
• after the OR has been called they are all bunched together in the insertion box. so LaTeX has to make a decision where to place them, eg first or last. currently it is last
• So in your example they are reinserted after the \section [N.B. \subsubsection in your case], but then LaTeX determines to break before the section [N.B. subsubsection], hence the result.

Doing it first has the opposite problem (and one that would happen more requently I guess) that you might pick up a footnote text where the mark then ends up on the following page.

For this problem the correct approach is to use \holdinginserts when calling the OR but this is not easy to integrate into the algorithm as it is a major change.

For the specific case that you are running into, a possible workaround was also given; though if your document is more complicated it may break some other things. The fix given involves loading etoolbox and patching how floats are handled, so you can try adding

\usepackage{etoolbox}
\makeatletter
\patchcmd\end@float{\@cons\@currlist\@currbox}
{\@cons\@currlist\@currbox
\global\holdinginserts\@ne}
{}{}

\apptocmd\@specialoutput{\global\holdinginserts\z@}

\makeatother


to your preamble. On your MWE I tested it and it works.

• Thank you very much, and also thanks to @cgnieder for the hint/comment. I'm not familar with the TeX internal but the description at a high level makes sense. I tried it on my real document and it indeed seems to fix the issue. I do not notice any breakage which might be because I don't have any finely tweaked layout (trying to keep things automatic for exactly this reason). But just to be sure, do you have any idea anything that's more likely to be broken by this? – yuyichao Jan 5 at 17:47
• Also I have to say that I'm a bit surprised by how recent that issue/comment is... Surely someone should have hit this issue years ago = = .... – yuyichao Jan 5 at 17:49
• If you load other packages that does fancy stuff to floats which redefines \end@float then the patch may no longer be good. Also the according to Frank Mittelbach, the "computation" could be off if you change the page margins on the fly using \enlargethispage. Finally, it may also do weird things to \marginpars. – Willie Wong Jan 5 at 18:02
• OK, thx. I don't think I have any dynamic change of margin and no \marginpars either. I hope I don't have anything that redefines float environment ... In any case, now that I know it's related to float, it isn't THAT bad to do a review around all the figures (~20 of them) before I do my final submission... Much better than reading through 200 pages or trying to locate all the footnotes... – yuyichao Jan 5 at 18:07
• I dug a bit more and it is not really that recent. This bug has surfaced on and off and been reported at least a handful of times since the early 2000s. The early response was that "this could be solved with LaTeX3's \holdinginserts; so we should solve it when we migrate everything to LaTeX3." Of course nowadays the attitude toward "migration" is a bit different. – Willie Wong Jan 5 at 18:19

UPDATED

I added float and \begin{figure}[H] to make the figure appear after the \subsubsection

The footnote will stay until the end in the first page. (\vspace{17.5cm})

% !TeX TS-program = pdflatex

\documentclass[letter]{article}

\usepackage{setspace}

\usepackage{float}

\begin{document}

\small \rm
%\setstretch{2.0}

\doublespacing

a aj jfskdj pojsdf jasdfj jjiaosdjf jaisdojf ajsidfj oaijds fsojijf sd,

\vspace{17.5cm}

a aj jfskdj pojsdf jasdfj jjiaosdjf jaisdojf ajsid\footnote{fasu tuthwery ;xncdnbcd},
fpoiajsdfpoiajdskajsdpof  fiosd f asd faijdf a df a jfpo oiaf pa pfoija
fpoiajsdfpoiajdskajsdpof  fiosd f asd faijdf a df a jfpo oiaf pa pfoija
fpoiajsdfpoiajdskajsdpof  fiosd f asd faijdf a df a jfpo oiaf pa pfoija
fpoiajsdfpoiajdskajsdpof  fiosd f asd faijdf a df a jfpo oiaf pa pfoija
% Uncomment the following to fix the problem...
% fpoiajsdfpoiajdskajsdpof  fiosd f asd faijdf a df a jfpo oiaf pa pfoija

\begin{figure}[H]
\centering
\caption{
JHLHL Jlkjaklsdf jalksjdf kja;d fa;skldjf ;aksdjf japisodf