看看 listings 文档,用 frame = L
就是双线了。颜色自己查查手册了。示例如下:
\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.c}
(function (__global) {
var tmp0, tmp1,....;
tmp13 = function (a) {
var tmp14;
tmp14 = a;
return tmp14;
};
...
tmp16 = function (flag) {
...
tmp20 = tmp21 == tmp22;
if (tmp20) {
tmp26 = 'x';
tmp24 = __global[tmp26];
tmp25 = 1;
tmp23 = tmp24 * tmp25;
return tmp23;
}
...
tmp7 = tmp16(tmp10, tmp11);
...
}(typeof global === 'undefined' ? this : global));
\end{filecontents*}
\documentclass{scrartcl}
\usepackage{listings}
\usepackage{xcolor}
\lstdefinelanguage{HTML5}{
sensitive=true,
keywords={%
% JavaScript
typeof, new, true, false, catch, function, return, null, catch, switch, var, if, in, while, do, else, case, break,
% HTML
html, title, meta, style, head, body, script, canvas,
% CSS
border:, transform:, -moz-transform:, transition-duration:, transition-property:,
transition-timing-function:
},
% http://texblog.org/tag/otherkeywords/
otherkeywords={<, >, \/},
%ndkeywords={class, export, boolean, throw, implements, import, this},
comment=[l]{//},
% morecomment=[s][keywordstyle]{<}{>},
morecomment=[s]{/*}{*/},
morecomment=[s]{<!}{>},
morestring=[b]',
morestring=[b]",
alsoletter={-},
alsodigit={:}
}
\lstset{%
% Basic design
%backgroundcolor=\color{white},
basicstyle={\ttfamily},
frame=L,
% Line numbers
xleftmargin={0.75cm},
numbers=left,
stepnumber=1,
firstnumber=1,
numberfirstline=true,
% Code design
identifierstyle=\color{black},
keywordstyle=\bfseries,
ndkeywordstyle=\color{blue}\bfseries,
stringstyle=\color{black}\ttfamily,
commentstyle=\color{darkgray}\ttfamily,
% Code
language={HTML5},
tabsize=2,
showtabs=false,
showspaces=false,
showstringspaces=false,
extendedchars=true,
breaklines=true
}
\begin{document}
\lstinputlisting{\jobname.c}
\clearpage
The following lines lines shows how to~\dots
\lstinputlisting[firstline=1,lastline=7]{\jobname.c}
The following lines shows that \dots
\lstinputlisting[firstline=9,firstnumber=10]{\jobname.c}
\end{document}
效果:
问 使用 listings 宏包排版代码的时候,如何在行号和代码块之间加上一条竖线以区分代码和行号?