0

I am trying to move a subsection to the next page if the complete subsection (title, the text and the floats) do not fit on the same page.

I don't want the figure to appear before the text.

I tried multiple approaches but I don't even get it to work in this simple example.

  • minipage to group the complete subsection
  • Using filbreak before subsection
  • rewriting subsection command with obscure stuff I did not understand

So what is a working way to do it and what is a recommended way to do it?

EDIT: To be more clear. I want Subsection 2 moved to the next page, so that it is on the same page as the figures which belong into it. Because they fit on one page, they should be on one page.

green is one subsection, which fits on a page but is split on two pages (yes the green is not drawn correctly, it should contain the complete figure)

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{etoolbox}
\usepackage{subcaption}

\title{SubsectionFloats}
\date{December 2022}

\begin{document}

\maketitle

\section{Introduction}
\subsection{Subsection 1}
\lipsum[2]
%\newpage ---------------   Here a new page should begin since subsection does fit on a single page but would be split by a pagebreak between text and figure if no newpage command is used. 
\subsection{Subsection 2}
\lipsum[5]
\begin{figure}
\begin{subfigure}{\textwidth}
    \centering
    \includegraphics[scale=0.5]{example-image-c}
    \caption{Caption1}
    \label{fig:my_label}
\end{subfigure}
\begin{subfigure}{\textwidth}
    \centering
    \includegraphics[scale=0.5]{example-image-c}
    \caption{Caption2}
    \label{fig:my_label2}
\end{subfigure}
\centering
\caption{Figures}
\end{figure}

\end{document}
1
  • Is it absolutely necessary to treat the figure as a float? This seems to be a case where it could be better to simply set \includegraphics in place, and use \captionof. Commented Jan 13, 2023 at 21:01

1 Answer 1

0

I don't really understand what you want. You say if a subsection is too long then move it to the next page. But on the next page it will be too long so move to the next page, and so on and so on. Just manually use \newpage where you want it.

2
  • Mhh. I mean there is already content on a page. So only 1/2 of a page is free. Then I want the next subsection AND it's figure to go on the next page. This way the subsection text is on the same page as its figure. But Latex will always place the text of the second subsection on the half full page. And the figure on the next page, since it does not fit.
    – Raros
    Commented Dec 14, 2022 at 12:14
  • 1
    Then manually use \newpage. Commented Dec 15, 2022 at 19:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .