\documentclass{article}
\usepackage{listings}
\usepackage{caption}
\lstset{
language=C++,
basicstyle=\small\ttfamily,
numbers=left,
numbersep=5pt,
xleftmargin=20pt,
frame=tb,
framexleftmargin=20pt
}
\renewcommand*\thelstnumber{\arabic{lstnumber}:}
\DeclareCaptionFormat{mylst}{\hrule#1#2#3}
\captionsetup[lstlisting]{format=mylst,labelfont=bf,singlelinecheck=off,labelsep=space}
\begin{document}
\begin{lstlisting}[caption={test algorithm}]
#include
using namespace std;
int main()
{
cout << "Welcome to the wonderful world of C++!!!\n";
return 0;
}
\end{lstlisting}
\end{document}
发表评论 取消回复