标题样式图:
实现代码如下:
\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}选自:http://tex.stackexchange.com/questions/73392/how-to-make-lstlisting-look-exactly-like-the-algorithm-environment
发表评论 取消回复