Visual indicator when a float is too tall

LaTeX makes a warning in the log, you can make it print something at the same time:

enter image description here

\documentclass{article}

\usepackage{color}
\makeatletter


\def \@largefloatcheck{%
  \ifdim \ht\@currbox>\textheight
    \@tempdima -\textheight
    \advance \@tempdima \ht\@currbox
    \@latex@warning {Float too large for page by \the\@tempdima}%
    \global\setbox\@currbox\hbox{%
      \box\@currbox
      {\color{red}\smash{\llap{FLOAT TOO BIG}}\vrule width 5pt}}%
    \ht\@currbox \textheight
  \fi
}

\makeatother
\begin{document}


\begin{figure}

\rule{2cm}{19cm}
\caption{a figure}
\end{figure}

\end{document}

Note the \smash here is added to fix the issue raised in comments that the original code could loop for some fonts. Without \smash I was assuming that the uppercase text FLOAT TOO BIG would have no depth, but the font metrics of some fonts do give capitals non zero depth.


The overfull rule works for horizontal boxes only.

Violations into the footer area can also be seen more easily, if there is a box around the body area. Package geometry marks the page layout with boxes, if it is uses with option showframe. If geometry is not uses otherwise, then option pass notifies geometry to not touch the layout parameters:

\usepackage[pass, showframe]{geometry}

Tags:

Floats