定制lstlisting 的标题
\renewcommand*\thelstnumber{\arabic{lstnumber}:}
\DeclareCaptionFormat{mylst}{\hrule#1#2#3}
\captionsetup[lstlisting]{format=mylst,labelfont=bf,singlelinecheck=off,labelsep=space}
\documentclass{article}
\usepackage{listings}
\usepackage{caption}
\lstset{
language=C++,
basicstyle=\small\ttfamily,
numbers=left,
numbersep=5pt,
xleftmargin=20pt,
showstringspaces=false, %去掉空格时产生的下划的空格标志, 设置为true则出现
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},label={lst1}]
#include
using namespace std;
int main()
{
cout << "Welcome to the wonderful world of C++!!!\n";
return 0;
}
\end{lstlisting}
\end{document}
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 changzeyan@foxmail.com