|||
\usepackage{graphicx}\usepackage{xcolor}\usepackage{listings}\lstset{%alsolanguage=Java,%language={[ISO]C++}, %language为,还有{[Visual]C++}%alsolanguage=[ANSI]C, %可以添加很多个alsolanguage,如alsolanguage=matlab,alsolanguage=VHDL等%alsolanguage= tcl,alsolanguage= XML,tabsize=4, %frame=shadowbox, %把代码用带有阴影的框圈起来commentstyle=\color{red!50!green!50!blue!50},%浅灰色的注释rulesepcolor=\color{red!20!green!20!blue!20},%代码块边框为淡青色keywordstyle=\color{blue!90}\bfseries, %代码关键字的颜色为蓝色,粗体showstringspaces=false,%不显示代码字符串中间的空格标记stringstyle=\ttfamily, % 代码字符串的特殊格式keepspaces=true, %breakindent=22pt, %numbers=left,%左侧显示行号 往左靠,还可以为right,或none,即不加行号stepnumber=1,%若设置为2,则显示行号为1,3,5,即stepnumber为公差,默认stepnumber=1%numberstyle=\tiny, %行号字体用小号numberstyle={\color[RGB]{0,192,192}\tiny} ,%设置行号的大小,大小有tiny,scriptsize,footnotesize,small,normalsize,large等numbersep=8pt, %设置行号与代码的距离,默认是5ptbasicstyle=\footnotesize, % 这句设置代码的大小showspaces=false, %flexiblecolumns=true, %breaklines=true, %对过长的代码自动换行breakautoindent=true,%breakindent=4em, %escapebegin=\begin{CJK*}{GBK}{hei},escapeend=\end{CJK*},aboveskip=1em, %代码块边框tabsize=2,showstringspaces=false, %不显示字符串中的空格backgroundcolor=\color[RGB]{245,245,244}, %代码背景色%backgroundcolor=\color[rgb]{0.91,0.91,0.91} %添加背景色escapeinside=``, %在``里显示中文%% added by http://bbs.ctex.org/viewthread.php?tid=53451fontadjust,captionpos=t,framextopmargin=2pt,framexbottommargin=2pt,abovecaptionskip=-3pt,belowcaptionskip=3pt,xleftmargin=4em,xrightmargin=4em, % 设定listing左右的空白texcl=true,% 设定中文冲突,断行,列模式,数学环境输入,listing数字的样式extendedchars=false,columns=flexible,mathescape=true% numbersep=-1em}\begin{document}
LaTeX 中在 lstlisting 环境下如何引用某句代码的行号https://docs.pingcode.com/ask/227671.html
参考与来源[1]https://blog.csdn.net/qq_44885695/article/details/124258901
[2]https://www.cnblogs.com/ediszhao/p/4547583.html
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2026-2-25 21:47
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社