[Tex/LaTex] Float positioning [ht] not working for algorithm

algorithm2efloatspositioning

I am using the package algorithm2e.
I have a document with several algorithms. I use the float position option [ht], but all my algorithms are positioned at the end of the chapter; none at the position or on the next page.
I tried the package float as suggested in this post Floating an algorithm?.
But the algorithms looked very different and wrong after that.
Does anyone have an idea how I position my algorithms at 'here' or the top of the next page?

Best Answer

For any kind of float, using an optional argument that does not include p vastly increases the chance of floats going to the end of document. Perhaps [!htp] will do what you want.

Here ! says LaTeX should ignore most of the stylistic constraints such as the proportion of the page allowed for floats or the number of floats per page and so it will place the floats if the page breaks are not unacceptably bad.

Note [!htp] disallows bottom floats you could also use [!ht] which would disallow page floats but whenever you shorten the optional argument in this way you remove some possibilities for float positioning so make it more likely the float can not be positioned at all in which case it will be held up until end of document.

Related Question