0

Why, in some instances, is the text Here is some text presented before the picture.jpg in the final document, please?

\begin{figure}[h]
\centering
\includegraphics[width=...]{picture.jpg}
\caption{The best caption in the world.}
\end{figure}

Here is some text.

I have had similar problems when doing \protect\footnotemark inside the \caption{...}, when the \footnotetext{...} which is supposed to come afterwards, is presented before the image.

O0123
  • 1,773
  • @jon I am not completely aware of what "floating" exactly encompasses in a LaTeX context, but I don't think I need that in any way for my purpose. So, I would be very glad if a solution could be given by circumventing the "floating". – O0123 Apr 19 '16 at 03:58
  • Don't footnote a caption (in most circumstances). The caption is already a special kind of 'note', so footnoting a caption is rather like footnoting a footnote.... – jon Apr 19 '16 at 04:00
  • @jon The nice thing about the figure environoment is the automatic line-spacing after the figure. – O0123 Apr 19 '16 at 04:22
  • They are in the answer below..? I'm afraid I can't guess what 'fiddled around with the center environment' means. – jon Apr 19 '16 at 04:28
  • @jon True, it helps with the spacing, but the captions (I mean \captionof's of course) are not centered along with the pictures. I mean: in your MWE answer they are, but when I encompassed \captionof inside center environment in my document of purpose, they weren't ( but aligned completely left sometimes, or a little to the left) ... I'll find the bug, I hope. Another bug (in my document of purpose) is that the center environment shifts some pictures to the right. – O0123 Apr 19 '16 at 04:32
  • Can you edit your question to include some minimal but self-contained and compilable code that demonstrates this problem? – jon Apr 19 '16 at 04:33
  • If it is in the center environment, just make a copy of your file, comment out all the text except for one or two paragraphs on either side of the center environment, and try to compile that. Then comment out packages that are clearly not related to uncommented text; then try to comment out the ones that probably aren't related; then try to comment out some more; etc., etc. – jon Apr 19 '16 at 04:51
  • Hmm, that's simply not true in general (unless you have unclosed environments and so on). Doesn't the error message say why? Note that warnings are not errors. Are you loading other caption-related packages? – jon Apr 19 '16 at 04:57
  • @jon Very strange: I found that deleting (or even just commenting out) the \abstract{...} (near the top of the document) fixes the issue of having horizontally shifted images almost all the way at the bottom of the document. – O0123 Apr 19 '16 at 05:02
  • Good luck. I do wonder if it's due to some interaction between capt-of and another captioning package (in case you choose to explore further). – jon Apr 19 '16 at 05:16
  • @jon I now reverted to original set-up (which solves the issue of the shifted images), and used \usepackage[section]{placeins} to stop floating. But, an issue I am having is that some (I'm using hyperref) footnotes don't link back to the original footnote-placing (inside an image's caption), but rather multiple pages early. EDIT: Now, some footnotes don't appear at all ... – O0123 Apr 19 '16 at 05:21
  • Try adding \phantomsection before the \footnotemark, I guess. But I really must stress that claiming 'phenomenon X happens' without the code that produces the effect is asking others to pull out crystal balls and call on the spirits to try to divine why X is happening. These are all legitimate questions, but you need to ask them with a MWE. – jon Apr 19 '16 at 17:30

1 Answers1

2

The solution here is probaly just to not let them 'float' via the \begin{figure} ... \end{figure} environment. But one can also use the \FloatBarrier command from the placeins package.

\documentclass{article}
\usepackage{lipsum, mwe}% just for this example
\usepackage{capt-of}

% uncomment the \FloatBarrier to see it in action
\usepackage{placeins}
% Note you could load it as
%\usepackage[section]{placeins}
% this would include a \FloatBarrier in each use of \section

\begin{document}

\lipsum[1]

\begin{center}
\includegraphics{example-image}
\captionof{figure}{Example Caption}
\end{center}

\lipsum[1]

\begin{figure}[h]
\centering
\includegraphics{example-image}
\caption{The best caption in the world.}
\end{figure}

%\FloatBarrier
Here is some text.

\begin{figure}[h]
\centering
\includegraphics{example-image}
\caption{The best caption in the world.}
\end{figure}

%\FloatBarrier
Here is some text.

\begin{figure}[h]
\centering
\includegraphics{example-image}
\caption{The best caption in the world.}
\end{figure}

%\FloatBarrier
Here is some text.

\begin{figure}[h]
\centering
\includegraphics{example-image}
\caption{The best caption in the world.}
\end{figure}

%\FloatBarrier
Here is some text.

\end{document}
jon
  • 22,325