I'm starting my experiment with LaTeX, i'm writing an article and all that I want is to embed an algorithm inside normal text, this is my code:
\documentclass{article}
\usepackage{algorithmic}
\begin{document}
\section{Lettura file .gpx}
Lorem ipsum ...
\algsetup{indent=1.7em}
\begin{algorithm}
\caption{Alg capt}
\label{alg1}
\begin{algorithmic}[1]
... algorithm here...
\end{algorithmic}
\end{algorithm}
\end{document}
This is fully working but algorithmic uses a pagebreak automatically, how can I avoid this break and show the algorithm immediately after "lorem ipsum" part?
Best Answer
Here are some suggestions:
If you're adding your algorithm inside the
algorithm
float, then it will float according to the "float specifiers" given as the optional argument to thealgorithm
environment. For exampleTo force the float to be less float-y, add
!
to the float specifier. However, as suggested by thefloat
package, this still remains a "suggestive specifier". Instead, the package provides the additionalH
float specifier which tells LaTeX to "PUT IT HERE!"Use the
algorithmx
package. It is very similar toalgorithmic
, but allows for more flexibility. Here's a short, yet complete, minimal example (from thealgorithmicx
package documentation).If you wish to have the algorithm break across the page boundary, you have to set things up differently. I've incorporated a
breakablealgorithm
environment below.The above redefinition of
\caption
assumes that it will be placed where it's located in the algorithm; specifically at the top. Rule definitions were taken from thefloat
package's\@fs@ruled
construction.