2

Sometimes a figure I want to place at the bottom of a page is placed on the next page regardless of the available space. I, finally, did some testing and realized that the height of a figure may not be more than 25% of the \textheight for it to be placed at the bottom. And, at least in my tests, it may not exceed 65% of the \textheight to be placed at the top.

UPDATE: As described by the comments and the linked explanation of the placing algorithm in most cases adding ! to the positioning parameters should solve the problem. Following a working example with bottom positioning and a page of follow-up text:

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\begin{document}

Some text here.

\begin{figure}[!b]% \includegraphics[draft, height=0.40\textheight, width=0.6\columnwidth]{example-image}% \centering \caption{Relaxing constraints with !, this figure (40% textheight) will be placed at the bottom, too.}% \label{}% \end{figure}

\lipsum[1-5]

\end{document}

Placement with full page of text

However, in my original document, the text and figure is followed by a minipage which does not fit into the same page and needs to be placed on the next page (in fact, it is a rather lengthy lstlisting which I don't want to break up). Adding such a minipage to the above code yields strange behavior. The figure is placed on the first page but not at the bottom. Instead it seems to behave as if the h positioning has been used:

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\begin{document}

Some text here.

\begin{figure}[!b]% \includegraphics[draft, height=0.40\textheight, width=0.6\columnwidth]{example-image}% \centering \caption{Relaxing constraints with !, this figure (40% textheight) will be placed at the bottom, too.}% \end{figure}

\begin{minipage}{\linewidth} \lipsum[1-5] \end{minipage}

\end{document}

Placement with full minipage

The same behavior can be observed when I add the text without a minipage but trigger a pagebreak before the lipsum. I assume minipage may introduce a pagebreak or equivalent if it doesn't fit onto a page.

Last but not least, a clearpage before the minipage solves the problem and places the figure at the bottom while, as far as I understand the algorithm, a figure may only be placed on subsequent pages when the layouter reaches a clearpage:

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\begin{document}

Some text here.

\begin{figure}[!b]% \includegraphics[draft, height=0.40\textheight, width=0.6\columnwidth]{example-image}% \centering \caption{Relaxing constraints with !, this figure (40% textheight) will be placed at the bottom, too.}% \label{}% \end{figure}

\clearpage \begin{minipage}{\linewidth} \lipsum[1-5] \end{minipage}

\end{document}

Placement with clearpage before minipage

I love such corner cases as I constantly seem to run into them in every aspect of my life. Maybe someone can explain what happens here and how to deal with the situation in a way which does not fall back on you ten pages later in the document ;)

Best wishes, Stefan

Johnson
  • 227
  • 1
    The default definition are that \topfraction is 0.7 and \bottomfraction is 0.3. You can of course redefine those. See How to influence the position of float environments like figure and table in LaTeX? for more details. (This might be in fact a duplicate). – campa Dec 11 '20 at 13:32
  • Wow, that was fast. In my research, I didn't come across your linked topic. Exactly, what I was looking for. Thank you! You probably should have posted an answer instead of the comment. – Johnson Dec 11 '20 at 13:36
  • 2
    As the other question has a detailed answer I see no need for posting an extra answer here. If you agree, I'll mark this question as duplicate. But I wish I could upvote you more than once for the thorough testing :-) – campa Dec 11 '20 at 13:38
  • Feel free to call it duplicate. It indeed is. I will upvote your comment, then. Thank you, again! – Johnson Dec 11 '20 at 13:41
  • 1
    A simple \begin{figure}[bp!]% will do it, – Simon Dispa Dec 11 '20 at 13:55
  • I tried that in advance in my original document but it only worked if the figure is followed by a \clearpage. I roughly read through the linked explanation, now, but can not really attribute that behavior to the description of the algorithm. It even seems to contradict the described behavior. I will update my question as something seems to clash there which is not described in the linked topic. – Johnson Dec 11 '20 at 14:28
  • 1
    @campa Is there a way to "reopen" the question. It turns out that after taking my use case into consideration more closely the question is not a duplicate. – Johnson Dec 11 '20 at 15:34
  • 1
    I've voted for reopening. – campa Dec 11 '20 at 15:35
  • minipage does not allow pagebreaks. You may use a list environment or adjustbox env from changepage package, see minipage with page break. – muzimuzhi Z Dec 12 '20 at 09:26

1 Answers1

3

Adding such a minipage to the above code yields strange behavior. The figure is placed on the first page but not at the bottom. Instead it seems to behave as if the h positioning has been used:

This is a misunderstanding of b which does not imply flush to bottom of the page, but rather "place below the text" so as the page is short, the image, even using b, is relatively high on the page.

if you add \flushbottom to the preamble you get

enter image description here

Although as there is no available stretchy space on that page you are warned

Underfull \vbox (badness 10000) has occurred while \output is active

Note you should not routinely use ! as in [!b] as ! means "ignore user-set constraints on this instance" It is better to set more suitable constraints, eg set \bottomfraction to 0.7 rather than 0.3, then use [bp]

I assume minipage may introduce a pagebreak or equivalent if it doesn't fit onto a page.

minipage has no positioning or spacing code at all, it simply works like a large letter. If a minipage does not fit then the page break may be needed but as in the example here, no special glue or penalties are added so the spacing depends on any other glue that may be on the page.

David Carlisle
  • 757,742
  • Interesting, I never realized my misunderstanding of the b option. Everywhere you look the option is described as "Position at the bottom of the page."

    I am still puzzled why adding a \clearpage results in an output similar to your proposal. I am also not sure what the p option helps in your alternative approach. "Put on a special page for floats only." doesn't seem to be what I want here.

    – Johnson Dec 14 '22 at 08:25
  • @Johnson you should almost always include p if you use the option at all. For example in article floats are not allowed to take more than 70% of a text page, so if you have a float that is bigger than that and has [htb] it can not be placed anywhere so it, and all following floats, will drift to the end of a document unless forced out by \clearpage (which over-rides the option and uses the p layout in all cases) – David Carlisle Dec 14 '22 at 09:21
  • Thanks for the clarification. I never encoutered such a case yet but I'll keep that in mind. – Johnson Dec 15 '22 at 09:25