37

In my document, I have figures that have a rather long caption. The code I use to include them looks like this:

\begin{figure} \begin{center} \includegraphics[width=\textwidth]{../fig.pdf} \caption[Short caption]{Fairly long text...} \end{center} \end{figure} 

For some of the figures, I keep getting warnings like this one:

LaTeX Warning: Float too large for page by 2.38557pt on input line 339. 

I can't see anything wrong with the figures in the output document, but it makes the compilation output harder to read because it is full of such warnings.

What am I doing wrong, and how can I get rid of these warnings?

1
  • 1
    I was struggling a lot with different solutions including playing with \vspace{-Xmm}. Until I came up with this solution that perfectly works for huge images/tables: stackoverflow.com/a/44439837/2961878 Commented Jun 8, 2017 at 15:31

5 Answers 5

36

The warnings tell you that the float (figure and caption) are too long for staying in a page. You will get rid of many of those warnings if you avoid the center environment:

\begin{figure} \centering \includegraphics[width=\textwidth]{../fig.pdf} \caption[Short caption]{Fairly long text...} \end{figure} 

(it should be avoided anyway, see Should I use center or centering for figures and tables?).

For pretty high figures you might also want to shorten their width, say 0.95\textwidth or less. LaTeX won't apply such a transformation for you: the warning simply tells that a float needs attention, but how to solve the problem depends on factors that only a human can evaluate properly.

5
  • How could one suppress this warning but not change the page layout or the size of the figure? Commented Apr 23, 2018 at 14:38
  • @lblb Why would you suppress the warning? Commented Apr 23, 2018 at 16:51
  • @egreg: I get this warning myself and I just want to leave the offending figure exactly as it is. It's likely both too wide and too long for the page. To be clear I only want to suppress the one warning for the one figure, not all warnings of this kind. Commented Apr 23, 2018 at 20:29
  • @lblb This mostly depend on the actual code and why you don't care about the excess height. Commented Apr 23, 2018 at 20:31
  • @egreg: I found a solution for my case: tex.stackexchange.com/questions/404301/… \enlargethispage didn't work for the float page. Commented Apr 23, 2018 at 20:38
13

If the overfullness is not actually a problem: it worked for me to add \vspace{-Xpt} before the \end{figure}.

In my case the complaint was about an utterly inconsequential 0.04999pt and so I did not want to split the figure or do anything else to the input, just get the useless-in-this-case warning to go away.

3
  • 1
    Great! I added the same \vspace{-Xpt} before the end of the table and it worked. I had a long table though, and I needed to use top and bottom margins. Commented May 19, 2017 at 18:29
  • This worked like a a charm! Commented May 15, 2019 at 9:59
  • FYI, I am using table and landscape, and had to put it before \end{table} Commented Aug 2, 2021 at 16:06
1

In case one has figures boxed (e.g. with the floatrow package) the \vspace solution disrupts the boxing (i.e. the box will cut the figure at \textheight). The problem can be fixed by extending the text area of the floatpage.

\makeatletter \newenvironment{largefigure}[1][0pt]{ \clearpage % finish last page and flush previous floats % save current textheight \newlength{\@prevtextheight}\setlength{\@prevtextheight}{\textheight} % extend textheight and recompute internal float parameters \setlength{\textheight}{\textheight + #1} \global\@colht\textheight % reset \@colht \global\@colroom\textheight % reset \@colroom \@floatplacement % force float to appear at top of page \setlength{\@fptop}{0pt} \begin{figure}[!p] }{ \end{figure} \clearpage % flush the float % restore textheight and all \setlength{\textheight}{\@prevtextheight} \global\@colht\textheight \global\@colroom\textheight \@floatplacement \setlength{\@fptop}{0pt plus 1fill} } \makeatother 

The solution to your problem then becomes:

\begin{largefigure}[3pt] % extend text area by 3pt \cenetring \includegraphics[width=\textwidth]{../fig.pdf} \caption[Short caption]{Fairly long text...} \end{largefigure} 
0

In contrast to actually changing the dimensions of an offending image or float, which is too tall and/or too wide for the text area, I personally often work with carefully scaled graphics that only overshoot the margins by a few millimeters. I would employ these two techniques to silence these warnings gracefully:

\documentclass{article} \usepackage{graphicx} \usepackage[showframe]{geometry} \begin{document} % image too wide \begin{figure} \makebox[\textwidth][c]{% fix, centers image in textblock \includegraphics[width=1.1\textwidth]{example-image} } \end{figure} % image too tall \begin{figure} \includegraphics[height=1.1\textheight]{example-image-golden-upright} \vspace{-60pt} % fix \end{figure} \end{document} 

screenshot of MWE

The first one handles bad box warnings and places the image inside a \makebox, which will here center the image on the text area no matter how wide it is. The second example deals with too high images: \enlargethispage doesn't work with float environments (see \enlargethispage command inside a float), so we need to insert a negive height at the end of the figure environment contents to fool LaTeX successfully.

-2

I think this works well in clearing the error message. Inserting the code line \vspace{-60pt} before the \end{figure}.

\begin{figure} \makebox[\textwidth][c]{% fix, this centers image in textblock \includegraphics[width=1\textwidth]{image} } \vspace{-60pt} % fix \end{figure} 
1
  • 4
    This is rather bad advice, at least in its present form without considering the possible side effects. You should not add (negative or positive) space at the very beginning or very end of a float like figure. Floats can float and if it floats it can be placed somewhere, where the (negative or positive) space causes harm. Apart from that, this possibility has already been mentioned in another answer and therefore contributes nothing new to answer the question. Commented Aug 20, 2024 at 6:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.