I want the floating block used in algorithm2e at the page's top instead of the middle. Here is my sample code with this Tex SX link's help:
\documentclass{article}
\usepackage{lipsum,mathtools}
\usepackage[noend,ruled,lined]{algorithm2e}
\usepackage{hyperref}
\usepackage{booktabs}
\usepackage{float}
\makeatletter
\setlength{@fptop}{0pt}
\setlength{@fpbot}{0pt plus 1fil}
\makeatother
\setlength{\intextsep}{13pt}
\newenvironment{SpacingAlgorithm}[2]{
\begin{algorithm}[ht]
\caption{#1}\label{alg:#2}
}
{
\end{algorithm}
}
\begin{document}
\lipsum[1]
\begin{SpacingAlgorithm}{1}{1}
\If{$1<2$}{
test
}
\end{SpacingAlgorithm}
\lipsum[1]\par
\lipsum[1]\par
\begin{itemize}
\item test
\end{itemize}
% \clearpage
\begin{SpacingAlgorithm}{2}{2}
\If{$1<2$}{
test
}
\end{SpacingAlgorithm}
\begin{SpacingAlgorithm}{3}{3}
\If{$1<2$}{
test
}
\end{SpacingAlgorithm}
\begin{itemize}
\item test
\end{itemize}
\end{document}
Then the pdf shows (Here I posted one small image to be better viewed for the mobile user):
Then I followed this Tex SX link, but it will make the contents after \begin{SpacingAlgorithm} also in one new page which may be not convenient if the floating block is very big causing one big blank area in the leaving page (See the above commented % \clearpage).
I also read this Tex SX link, but the H option in the \usepackage{float} is not available for algorithm block.
Q: How to make the above two algorithm blocks more condensed at the new page, i.e. not having one large blank area between them?
Edited:
After viewing this comment
- I checked the doc. The
Hoption in the\usepackage{float}can't be combined with other parameters. Also, althoughHwill make the above algorithm blocks condensed, I found the above\setlength{\intextsep}{13pt}won't work with it although the doc doesn't say it explicitly, but I need the\setlength{\intextsep}{13pt}feature. - I updated the above codes by removing
!and others, the figure is still same as before.

!means ignore the constraints so it's hard to do force any behaviour while you have!. Also ifHis defined it is defined for all float types including algorithms. – David Carlisle Nov 17 '23 at 15:04\setlength{\intextsep}{13pt}feature withHoption. I use\par\addvspace{10pt} \begin{algorithm}[H]and\end{algorithm} \vspace{10pt}, although maybe it is not one good solution for this specific problem. The modified codes can be seen here. Hope that someone can improve my solution. Thanks in advance. – An5Drama Nov 18 '23 at 00:35ltoutput.dtxfile and found the\makeatletter\setlength{\@fptop}{0pt}\setlength{\@fpsep}{3pt}\makeatothercan solve the above problem. See the codes which is a bit different from the above in my 2nd comment. Hope this can help the future readers. – An5Drama Nov 19 '23 at 12:32