# Algorithm caption should be on top and and flushed left

I want the caption of my algorithm to be on top and flushed left:

\documentclass{article}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}
\begin{document}

\begin{algorithm}
\caption{Sketch of our Compression Algorithm}
\label{fig:GENIDEA}
\begin{algorithmic}[1]
\While{Input contains characters}
\State Find matching reference block $B$ for current input position
\State Perform referential compression with respect to $B$ until we cannot find long'' matches anymore
\EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}


## 2 Answers

"on top" can be realized using \restylefloat offered by the float package which is used by the algorithm package. (Unfortunately the algorithm package does not offer an package option plaintop for that.)

"flushed left" can be realized using \captionsetup[algorithm]{...} offered by the caption package.

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}

% Change float style of algorithm from "ruled" to "plaintop"
\floatstyle{plaintop}
\restylefloat{algorithm}

% Make algorithm captions left-aligned
\usepackage{caption}
\captionsetup[algorithm]{singlelinecheck=off}

\begin{document}
\begin{algorithm}
\caption{Sketch of our Compression Algorithm}
\label{fig:GENIDEA}
\begin{algorithmic}[1]
\While{Input contains characters}
\State Find matching reference block $B$ for current input position
\State Perform referential compression with respect to $B$ until we cannot find long'' matches anymore
\EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}


• Figure caption is affected. Is there another way? – jeecabz Jan 11 '13 at 10:24
• @jeecabz In what way the figure caption is affected? (This should not happen and is not happening at my PC if I extend my example code with a figure.) – user2574 Jan 11 '13 at 20:25
• My apology. I miss some of the data when copying your code.. thanks – jeecabz Jan 12 '13 at 6:03
• @jeecabz I'm glad it works now for you, too. But why have you deleted your own answer? (If you have the possibility to undelete it please do so.) Using floatrow instead of float is a valid and mentionable alternative since the algorithm package work with both of them. – user2574 Jan 12 '13 at 8:47
• my answer is now undeleted. – jeecabz Jan 12 '13 at 10:55

I found the answer of my own question.

\documentclass{article}
\usepackage{floatrow}
\usepackage[plain]{algorithm}
\floatsetup[algorithm]{capposition=top}
\usepackage{caption}
\captionsetup[algorithm]{singlelinecheck=off}
\usepackage{algpseudocode}
\begin{document}

\begin{algorithm}
\caption{Sketch of our Compression Algorithm}
\label{fig:GENIDEA}
\begin{algorithmic}[1]
\While{Input contains characters}
\State Find matching reference block $B$ for current input position
\State Perform referential compression with respect to $B$ until we cannot find    long'' matches anymore
\EndWhile
\end{algorithmic}
\end{algorithm}

\end{document}