0

I am trying to set up the figure float in such a way that if there in not enough space after the text in that page, it goes to the top of the next page. Then the text after that float is written in the available space and so on. So I've tried [!ht]. and it works when there is sufficient text available to go below the figure. BUT if there is no text after the figure, the figure goes the middle of the page irrespective of the specifier t !t. How to resolve this, such that even if there is no text after the figure, the figure remains at the top of the page.

I have tried \afterpage but it did not work.

I am pasting the figure block in my code for consideration.

(Also, If there is a better way to resize the subfigures keeping their aspect ratio, please let me know)

\begin{figure}[!ht]
\centering
\begin{subfigure}{0.48\textwidth}
\centering
   \adjincludegraphics[height=2.8in, keepaspectratio]{images/example-image1.png}
   \caption{}
   \label{label1} 
\end{subfigure}
\hfill
\begin{subfigure}{0.48\textwidth}
\centering
   \adjincludegraphics[height=2.8in, keepaspectratio]{images/exmaple-image2.png}
   \caption{}
   \label{label2}
\end{subfigure}
\captionsetup{width=0.85\textwidth, justification=centering}
\caption{The Caption}
    \label{fig:label}
\end{figure}

I am attaching the images for the two cases mentioned (1)1with no text after the fig, (2) 2with text after the fig.

With No text Afterwards With Text Afterwards

1
  • [ht] will alsways go here on the first page or at the top of the next page. \includegraphics keeps the aspect ratio by default, unless you specify both the width and the height. [keepaspectratio] is used to decide which specification is smaller. Jul 13, 2023 at 13:26

1 Answer 1

0

First, it is useful to read this guide. Basically what's happening is that you specified [!ht], but since you don't have enough room for h, and there isn't enough text for t to work for the next page, it is impossible to TeX to follow your directives. So effectively your figure is being placed on the subsequent pages with p.

So what you need to change is to force figures that are printed on a floats only page to float toward the top, and not vertically centered. To do so you can include in the preamble

\makeatletter
\setlength{\@fptop}{0pt}
\setlength{\@fpbot}{0pt plus 1fil}
\makeatother

You must log in to answer this question.

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