[Tex/LaTex] Cannot put Caption on a pseudocode of algorithm

algorithmic

I wrote an algorithm pseudocode using the \userpackage{algorithmic} and when i want to put a caption i get an error. This is the code:

\begin{center}
\begin{algorithmic}
\STATE $N\gets sizeof(\textit{input data})$\\
\textbf{Function} Twiddle(W, N, stuff)
\STATE $        W.r \gets cos(stuff.2.\Pi/N)$
\STATE $        W.i \gets -sin(stuff.2.\Pi/N)$\\
...
\IF{$N_{2}!=1$}
\STATE \textbf{Call} $radix-4(data[N_{2}.k1], N_{2})$
\ENDIF
\label{algo1}
\end{algorithmic}
\end{center}

Can someone help me on that and is there an alternative for this package that gives a better look.enter image description here

Best Answer

The algorithmic environment is not a floating environment, you have to use the algorithm wrapper environment. Note this environment cooperates with caption, so you can easily customise captions for this environment. Here is an example different from the default:

\documentclass{article}
\usepackage{fourier, erewhon}
 \usepackage{caption}
\usepackage{algorithm, algorithmic}%

\begin{document}

\begin{algorithm}\captionsetup{labelfont={sc,bf}, labelsep=newline}
  \caption{Tweedledee and Tweedledum}
  \begin{algorithmic}
    \STATE $N\gets sizeof(\textit{input data})$\\
    \textbf{Function} Twiddle(W, N, stuff)
    \STATE $ W.r \gets cos(stuff.2.\Pi/N)$
    \STATE $ W.i \gets -sin(stuff.2.\Pi/N)$\\
    ...
    \IF{$N_{2}!=1$}
    \STATE \textbf{Call} $radix-4(data[N_{2}.k1], N_{2})$
    \ENDIF
    \label{algo1}
  \end{algorithmic}
\end{algorithm}

\end{document} 

enter image description here

Related Question