I'm trying to force an algorithm to stay between two paragraphs, but after compilation, it shows up in the next page. My algorithm takes more than half a page and is something like:
\begin{algorithm}[tbh]
\caption{Game}
\begin{algorithmic}
\State \bf{Initialize:} \normalfont
\begin{itemize}
\item \bf{A preferences:} \normalfont
\begin{itemize}
\item 1 for A
\item 2 for A
\item 3 for A
\end{itemize}
\item \bf{B preferences::} \normalfont
\begin{itemize}
\item 1 for B
\item 2 for B
\item 3 for B
\end{itemize}
\item \bf{Nature sets the laws:} \normalfont
\begin{itemize}
\item The nature chooses a set of incentives $\mathcal{R}$.
\end{itemize}
\end{itemize}
\State
\While {Set of Incentives $\mathcal{R}$ Exists}
\State
\State \bf{Defend:} \normalfont
\begin{itemize}
\item I
\item II
\item III
\end{itemize}
\State
\State \bf{Attack:} \normalfont
\begin{itemize}
\item I
\item II
\item III
\end{itemize}
\State
\State \bf{Nature:} \normalfont
\begin{itemize}
\item The Nature updates $\mathcal{R}$.
\end{itemize}
\State
\EndWhile
\end{algorithmic}
\end{algorithm}
It seems like [tbh]
is not working here.
Best Answer
To force a float to remain in a specific location, add the
float
package to your preambleand use the
[H]
float placement specifier. Done.The reason why the float didn't stay where it was supposed to is because it was probably too large to fit within the page in the first place. See How to influence the position of float environments like figure and table in LaTeX?. Most likely variables like
\topfraction
or\textfraction
caused the float to move onto page of its own.There might be some drawbacks of using the
[H]
float specifier, although minimal. See Drawbacks of theH
specifier.