For some reason, my figures get pushed to the end of the document. I tried begin{figure}[t], [h] and other options, but none helped. Any ideas how to get the figures to appear much earlier in the document, where they are approximately first mentioned in the .tex file?
8 Answers
Your figures are most likely too large and/or you tell LaTeX to place them at a position where they don't fit. So they are are pushed to the last position were they finally do: the end of the document.
Adding restrictions like [t] (top) or [h] (here, LaTeX has a habit of refusing it) doesn't help, but makes things worse! Actually removing all of that restrictions might help. There is a good reason why this argument to figure is optional! If you are using it add at least p so LaTeX can do float-only pages.
To fix this
you can allow more space for floats (figure and table) alike by redefining one or more of the following macros. The ...fraction ones define the fraction of the page with is allowed to be used on top or bottom etc. The ...number ones define the maximum number of floats at these positions.
The values below are examples from this TeX FAQ.
\renewcommand{\topfraction}{.85}
\renewcommand{\bottomfraction}{.7}
\renewcommand{\textfraction}{.15}
\renewcommand{\floatpagefraction}{.66}
\renewcommand{\dbltopfraction}{.66}
\renewcommand{\dblfloatpagefraction}{.66}
\setcounter{topnumber}{9}
\setcounter{bottomnumber}{9}
\setcounter{totalnumber}{20}
\setcounter{dbltopnumber}{9}
I wouldn't recommend to change your figures to non-floating ones because this gives bad layout.
- 757,742
- 262,582
-
16Thanks. I had
[t]on a figure that was too big. Removing[t]or changing it to[tp]worked for me. – geometrikal Aug 12 '14 at 02:53 -
5I had the exact same problem. I have the habit of adding [h] or [h!] to all my figures. Removing it fixed the issue for me and stopped pushing my floats to the end of the chapter. – Ahmed El Bokl Mar 19 '15 at 00:33
-
1[!htbp] works pretty well if you put it on every figure without having to think. You can always remove the p from small figures if they get placed on their own page. – WetlabStudent Jan 15 '17 at 12:33
-
4
-
5
-
1Thank you, completely removing the optional arguments
[...]of my float object worked for my problem as well. I had a big algorithm and by removing the arguments, latex eventually decided to split an enumerate, which is fine by me, as it doesn't push it to the end. – Adama Nov 18 '17 at 22:01 -
1@geometrikal Your comment fixes the problem for me too. I would encourage you to post it as an answer. – felipecrp Apr 16 '21 at 21:00
-
1
Note that this has been mentioned in a few places already. Here is a summary:
If you really want them to stay in place, you could just not put them in Floats. Then you can use either the caption or the capt-of package to add a caption to the figure.
However, I think that the most accepted method is to use the placeins package to have your floats placed in the section they appear in. You can also define \FloatBarriers to decide where floats should not go past.
Playing with the size of the figure, even for a couple of points, can also make a great difference in the placement while not changing much of the visual aspect.
- 1,224
-
2+1: While placeins doesn't stop figure migrating to be on their own page (because almost nothing short of resizing them can). It forced them to only migrate so far. Thus locking them down to there section (or subsection see http://tex.stackexchange.com/questions/118662/use-placeins-for-subsections). Thus solving many issues. Its almost always preferable (for my work at least) to have them be anywhere closer than the end of the document. – Frames Catherine White Oct 22 '14 at 03:48
-
Start with appropriate placement parameters for your float objects.
\begin{figure}[!ht]
% figure content
\end{figure}
The exclamation mark overwrites the internal values introduced by Martin and makes LaTeX "try harder" to place the float at the earliest possible place. It is documented in Appendix C.9 of the Lamport book.
- 46,014
-
1Neither
!hortwill do any good when the figure is larger then1-\textfractionor\topfraction. IMHO restricting a figure causes this issue more often then fixing them. – Martin Scharrer Feb 18 '11 at 10:07 -
7There was no talk of "
!hort", but of[!ht]. One single parameter is never good. And a figure with that size should be placed on its own float page by using[!p]as placement parameter. – Thorsten Donig Feb 18 '11 at 10:33 -
Thank you @ThorstenDonig! I was struggling with this for some time and solved it with a single character '!'. – Carser May 07 '14 at 19:43
-
Adding a "!" to my "hbt" did the job in my case. So I used "hbt!" for this figure, which had both a high image and a long caption. – Matthias Luh Jun 27 '23 at 16:11
As @Mortimer said, you can use \FloatBarrier from package placeins to add a barrier for figures, preventing the figures from going past that point.
However, this may inevitably create empty spaces in the page where you put the FloatBarrier. To fix this, use the package afterpage to create a smart placement of the \FloatBarrier command.
In short, instead of \FloatBarrier, use
\afterpage{\FloatBarrier}
This will automatically place the \FloatBarrier command immediately after the current page finishes, thus preventing any white space on the current page.
- 221
-
3
-
2
-
1Note that the float will be output automatically (without needing the rather fragile
\afterpageif the float has not been prevented from being on a float page (by use of an option such as[ht]) and if it is big enough to be output as a float page (\floatpagefraction) so if\floatpagefractionis set correctly\afterpage{\clearpage}should not normally be needed. – David Carlisle Mar 31 '16 at 09:51
I solved this problem by using \vspace{-20pt} after and before the caption to remove vertical space as shown:
\begin{figure}[t!]
\centering
\vspace{-20pt}
\centering\includegraphics[scale=0.8]{myfigure.eps}
\vspace{-10pt}
\caption{my caption}
\vspace{-20pt}
\label{fig:myfigure}
\end{figure}
- 6,730
- 4
- 28
- 58
- 39
-
8That is really not a good solution. It could have side-effects when you least expect them, especially if other aspects of your document change. I wouldn't recommend others use this approach as it is, at best, covering something up rather than solving it and, at worst, will cause far more problems than it solves. – cfr Dec 24 '14 at 02:54
I had this same problem. Replacing [t] with [htbp] helped:
\begin{table*}[htbp]
- h - where the table is declared (here)
- t - at the top of the page
- b - at the bottom of the page
- p - on a dedicated page of floats
- 119
-
2
-
2
-
5To future readers: the
table*environment, when used intwocolumnmode, won’t honor thehandbposition specifiers; if this may sound obvious forh, perhaps it is not forb(when used inonecolumnmode,table*is effectively equivalent totable). – GuM May 12 '17 at 21:39
The best way is clearly to use the \afterpage, pretty simple and worked perfectly fine for me after having issues with the brackets methods [!hf] and other useless methods...
- 1
-
4This answer is simply wrong, sorry.
[!hf]is a syntax error so wouldn't be expected to be useful and "use\afterpage" doesn't give any hint on how that command could be used to control floats (some possible mechanisms to control floats could use\afterpagein combination with other commands but it is almost never the recommended way) (I wrote afterpage and I'd not use it for that in a real document, most likely. – David Carlisle Mar 31 '16 at 09:45
This is working best for me:
htbp!
i.e.
\clearpage
\begin{figure}[htbp!]
\centering
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{download (20).png}
\caption{Image 1}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{download (21).png}
\caption{Image 2}
\end{subfigure}
\par\bigskip % This adds some vertical space between the rows
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{download (22).png}
\caption{Image 3}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{download (23).png}
\caption{Image 4}
\end{subfigure}
\par\bigskip
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{download (24).png}
\caption{Image 5}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{path_to_image_6.png}
\caption{Image 6}
\end{subfigure}
\par\bigskip
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{path_to_image_7.png}
\caption{Image 7}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\textwidth}
\includegraphics[width=\textwidth]{path_to_image_8.png}
\caption{Image 8}
\end{subfigure}
\caption{Images in a grid}
\end{figure}
- 2,110
- 1
- 1
endfloatpackage was being called. My problem was solved by simply commenting out that line (\usepackage[nolists,nomarkers]{endfloat}). I know that this is not a solution, however, I just wanted to share just in case. Sometimes this kind of knitty-gritties can make you lose hours :) – specstr Mar 16 '20 at 10:53