用listing制作类minted风格,如何在换页时也添加边框线?

发布于 2021-08-14 15:53:57

参照群主发布的[](https://www.latexstudio.net/index/details/index/mid/799.html),请问如何使得换页时,自动添加横线,使其变成完整的一个代码框。
效果图如下:
1.png
完整代码如下:

\documentclass[zihao=-4]{ctexart}
\usepackage{xcolor}
\usepackage{textcomp}
\usepackage{url}
\usepackage{listings}
\usepackage[margin=1.2in]{geometry}

\definecolor{darkgray}{rgb}{.4,.4,.4}

\lstdefinelanguage{JavaScript}{
  keywords={typeof, new, true, false, catch, function, return, null, catch, switch, var, if, in, while, do, else, case, break},
  ndkeywords={class, export, boolean, throw, implements, import, this},
  sensitive=false,
  comment=[l]{//},
  morecomment=[s]{/*}{*/},
  morestring=[b]',
  morestring=[b]"
}

\lstset{
    aboveskip={.3\baselineskip},
    basicstyle=\scriptsize\ttfamily\linespread{4},
    breaklines=false,
    columns=flexible,
    commentstyle=\color[rgb]{0.127,0.427,0.514}\ttfamily\itshape,
    escapechar=@,
    extendedchars=true,
    frame=single,
    identifierstyle=\color{black},
    inputencoding=latin1,
    keywordstyle=\color[HTML]{228B22}\bfseries,
    language=JavaScript,
    ndkeywordstyle=\color[HTML]{228B22}\bfseries,
    numbers=left,
    numberstyle=\tiny,
    prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
    stringstyle=\color[rgb]{0.639,0.082,0.082}\ttfamily,
    upquote=true,
    showstringspaces=false,
}

\lstset{literate=%
   *{0}{{{\color{darkgray}0}}}1
    {1}{{{\color{darkgray}1}}}1
    {2}{{{\color{darkgray}2}}}1
    {3}{{{\color{darkgray}3}}}1
    {4}{{{\color{darkgray}4}}}1
    {5}{{{\color{darkgray}5}}}1
    {6}{{{\color{darkgray}6}}}1
    {7}{{{\color{darkgray}7}}}1
    {8}{{{\color{darkgray}8}}}1
    {9}{{{\color{darkgray}9}}}1
}

\begin{document}
\title{用  \texttt{listings} 制作类 minted 风格}

\maketitle




显示效果如下:
\begin{lstlisting}

kk=2;
[mdd,ndd]=size(dd);
while ~isempty(V)
[tmpd,j]=min(W(i,V));tmpj=V(j);
for k=2:ndd
[tmp1,jj]=min(dd(1,k)+W(dd(2,k),V));
tmp2=V(jj);tt(k-1,:)=[tmp1,tmp2,jj];
end
tmp=[tmpd,tmpj,j;tt];[tmp3,tmp4]=min(tmp(:,1));
if tmp3==tmpd, ss(1:2,kk)=[i;tmp(tmp4,2)];
else,tmp5=find(ss(:,tmp4)~=0);tmp6=length(tmp5);
if dd(2,tmp4)==ss(tmp6,tmp4)
ss(1:tmp6+1,kk)=[ss(tmp5,tmp4);tmp(tmp4,2)];
else, ss(1:3,kk)=[i;dd(2,tmp4);tmp(tmp4,2)];
end;
end
dd=[dd,[tmp3;tmp(tmp4,2)]];V(tmp(tmp4,3))=[];
[mdd,ndd]=size(dd);
kk=kk+1;
end;
S=ss;
D=dd(1,:);
clc
clear
load truck.mat
%a 
% a=readmatrix('C:\Users\90678\Desktop\2021xlsx');
% a=a(1:9,5);
% save a
%zz 
% zz=readmatrix('C:\Users\90678\Desktop\3Dv2\2t\fujian3.xlsx');
% zz=zz(1:7,5);
% save zz
load zz
truck(:,4)=[]
truck1=truck;
load box.mat
load hw.mat
% for i=1:length(h)
%     box(1,i)=num2cell(hw(i,4:7),2);
%     box(2,i)=cellstr(['00' num2str(h(i))]);
%     box(3,i)=cellstr(['00' num2str(h(i))]);
%     box(4,i)=num2cell(0);
% end






\end{lstlisting}


核心定制代码如下:
\small
\begin{verbatim}
\lstset{
    aboveskip={.3\baselineskip},
    basicstyle=\scriptsize\ttfamily\linespread{4},
    breaklines=false,
    columns=flexible,
    commentstyle=\color[rgb]{0.127,0.427,0.514}\ttfamily\itshape,
    escapechar=@,
    extendedchars=true,
    frame=single,
    identifierstyle=\color{black},
    inputencoding=latin1,
    keywordstyle=\color[HTML]{228B22}\bfseries,
    language=JavaScript,
    ndkeywordstyle=\color[HTML]{228B22}\bfseries,
    numbers=left,
    numberstyle=\tiny,
    prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
    stringstyle=\color[rgb]{0.639,0.082,0.082}\ttfamily,
    upquote=true,
    showstringspaces=false,
}
\end{verbatim}

%\lstinputlisting{filename.js}
\end{document}

查看更多

关注者
0
被浏览
1.7k
LaTeXStudio
LaTeXStudio 2021-08-15
这家伙很懒,什么也没写!

你的这个需求,推荐你用 tcblisting 了,跨页什么的都是轻松驾驭。
image.png

1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览