Caption in algorithms in Latex
It is often useful for the algorithm produced by algorithmic to be “floated” to the optimal point in the document to avoid it being split across pages. The algorithm environment provides this and a few other useful features. Include it by adding the \usepackage{algorithm} to your document’s preamble.
Example
\documentclass[10pt,]{article} \usepackage{algorithmic} \usepackage{algorithm} \begin{document} \begin{algorithm} % enter the algorithm environment \caption{Calculate $y = x^n$} % give the algorithm a caption \label{alg1} % and a label for \ref{} commands later in the document \begin{algorithmic} % enter the algorithmic environment \REQUIRE $n \geq 0 \vee x \neq 0$ \STATE $y \Leftarrow 1$ \IF{$n < 0$} \STATE $X \Leftarrow 1 / x$ \STATE $N \Leftarrow -n$ \ELSE \STATE $X \Leftarrow x$ \STATE $N \Leftarrow n$ \ENDIF \end{algorithmic} \end{algorithm} \end{document}