I don't have an explanation for the behavior shown by the following two MWEs. Clearly, the footnote number is altered by the length of text in the caption. Please advise me as to why this strange behavior is occurring and how to avoid it?
MWE1:
MWE2:
MWE1 code:
\documentclass{article}
\usepackage[hmargin=2in,vmargin=5in]{geometry}
\begin{document}
\begin{figure}
\label{fig:temp}
\caption[Caption for LOF]{Caption\footnotemark. Some more text added here changes the footnote number in a length-dependent manner.}
\end{figure}
\footnotetext{Footnote text.}
\end{document}
MWE2 code:
\documentclass{article}
\usepackage[hmargin=2in,vmargin=5in]{geometry}
\begin{document}
\begin{figure}
\label{fig:temp}
\caption[Caption for LOF]{Caption\footnotemark. Less text rectifies the foonote number.}
\end{figure}
\footnotetext{Footnote text.}
\end{document}
Edit. In response to a comment, I provide a demonstration that the aberrant numbering can occur even if the caption is but a single line.
MWE3:
MWE3 code:
\documentclass{article}
\usepackage[hmargin=1.9in,vmargin=5in]{geometry}
\begin{document}
\begin{figure}
\label{fig:temp}
\caption[Caption for LOF]{Caption\footnotemark. Some more text added here changes the footnote number.}
\end{figure}
\footnotetext{Footnote text.}
\end{document}
Best Answer
As mentioned by @AxelSommerfeldt, the default document classes evaluates the
\caption{<stuff>}
twice in the case when<stuff>
is wider than a single line. Here's where the decision is made -\caption
is originally defined inlatex.ltx
, which subsequently calls\@makecaption
; taken fromarticle.cls
:It first stores the entire caption (say,
Figure 1: <stuff>
) inside a box:In your case, this evaluates
\footnotemark
. Then it tests to see whether the width of the box is wider than\hsize
(the width of the text block). If this is true, it sets the caption again which evaluates\footnotemark
for the second time:If the box width is less than
\hsize
, it centres it in another box of width\hsize
:The latter part motives the dual evaluation - the possibility to either set the caption as a paragraph block, or as a single, centred line. It's both a feature and a drawback in your particular case.
You may question that you were able to provide an example of a single caption that also yielded an incorrect
\footnotemark
. This is possible because the box-storing commandis set without regard for
\hsize
(the text block width). This implies that no stretching/shrinking occurs between words. If you add thegeometry
optionshowframe
to your example, you'll note that the caption fits exactly within the text block because of the inter-word glue that can shrink. However, setting the same in a box that doesn't require any glue usage shows that it is actually wider than\hsize
:How do you avoid this? You can either load the
caption
package that redefines\caption
appropriately (preferred), or set the\footnotemark
in a box that doesn't re-expand (or re-evaluate) when the caption is set twice:Although this works, it removes any
hyperref
capability.