May I suggest you to use tcolorbox
and its wonderful interaction with listings
. A little example (adjust the settings according to your needs):
\documentclass{article}
\usepackage[many]{tcolorbox}
\tcbuselibrary{listings}
\newtcblisting[auto counter]{mytcblisting}[2][]{
enhanced,
breakable,
arc=0pt,
outer arc=0pt,
listing only,
colback=white,
colframe=black,
fonttitle=\normalfont,
colbacktitle=white,
coltitle=black,
before skip=6pt,
after skip=6pt,
listing options={
columns=fullflexible,
basicstyle=\ttfamily\small,
numbers=left,
numbersep=10pt,
xleftmargin=15pt
},
title={{\bfseries Algorithm~\thetcbcounter:} #2},
#1
}
\begin{document}
\begin{mytcblisting}{Some example algorithm}
A test listing
and
some more
code
\end{mytcblisting}
\end{document}
The result:
