答案1
我可以建议你使用tcolorbox
以及与的精彩互动listings
。一个小例子(根据需要调整设置):
\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}
结果: