[Tex/LaTex] Algorithm caption should be on top and and flushed left

captionshorizontal alignment

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}

Best Answer

"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}

enter image description here