![分页符处的 tcblisting 问题](https://linux22.com/image/309980/%E5%88%86%E9%A1%B5%E7%AC%A6%E5%A4%84%E7%9A%84%20tcblisting%20%E9%97%AE%E9%A2%98.png)
我使用 tcolorbox 来显示我的列表,它实际上工作得很好。但如果我的列表中出现分页符,那么我预定义的“basicstyle”属性将被删除。我不知道为什么。也许有人有主意?
这是我的代码:
\begin{tcblisting}{
skin=enhanced,
colback=CSbackground,
boxrule=0pt,
arc=0pt,
outer arc=0pt,
top=-14.8pt,
bottom=-14.8pt,
colframe=red,
listing only,
left=-2.5pt,
right=-8pt,
overlay={\fill[CSnumberbg] ([xshift=-10pt]frame.south west) rectangle ([xshift=0pt]frame.north west);
\fill[CSnumberline] ([xshift=-10pt]frame.south west) rectangle ([xshift=-9pt]frame.north west);},
listing style=CSharp,
breakable,
bottomsep at break=14.8pt,
topsep at break=14.8pt
}
string s = "this is a string"
%many repetitions
string s = "this is a string"
\end{tcblisting}
结果:
这是一个分页符。
更新:
Thomas 的回复就是解决方案。谢谢你。不过,这里有一个更完整的示例,其中包含 Thomas 的修复。如果有人感兴趣的话。
\usepackage{listings}
\usepackage[most]{tcolorbox}
\definecolor{CSbackground}{RGB}{30, 30, 30}
\definecolor{CSkeywords}{RGB}{86, 156, 214}
\definecolor{CSstrings}{RGB}{214, 157, 133}
\definecolor{CScomments}{RGB}{96, 139, 78}
\definecolor{CSemph}{RGB}{78, 201, 176}
\definecolor{CSnumberbg}{RGB}{241, 241, 241}
\definecolor{CSnumberline}{RGB}{38, 169, 202}
\lstdefinestyle{CSharp}{
backgroundcolor=\color{CSbackground},
language=[Sharp]C,
frame=l,
framesep=5pt,
basicstyle=\footnotesize\ttfamily\color{White},
showstringspaces=false,
keywordstyle=\color{CSkeywords}\bfseries,
identifierstyle=\ttfamily,
stringstyle=\color{CSstrings},
commentstyle=\color{CScomments},
rulecolor=\color{CSbackground},
emph={GZipStream,StreamWriter,WebClient,additionalClasses},
emphstyle=\ttfamily\color{CSemph},
xleftmargin=5pt,
xrightmargin=5pt,
aboveskip=\bigskipamount,
belowskip=\bigskipamount,
showspaces=false,
showtabs=false,
breaklines=true,
breakatwhitespace=false,
escapeinside={(*@}{@*)},
numbers=left,
numbersep=1.1em,
stepnumber=1,
numberstyle=\tiny\color{Gray}
}
\begin{tcblisting}{
skin=enhanced,
colback=CSbackground,
boxrule=0pt,
arc=0pt,
outer arc=0pt,
top=-14.8pt,
bottom=-14.8pt,
colframe=red,
listing only,
left=-2.5pt,
right=-8pt,
overlay={\fill[CSnumberbg] ([xshift=-10pt]frame.south west) rectangle ([xshift=0pt]frame.north west);
\fill[CSnumberline] ([xshift=-10pt]frame.south west) rectangle ([xshift=-9pt]frame.north west);},
listing style=CSharp,
breakable,
bottomsep at break=14.8pt,
topsep at break=14.8pt,
colupper=white
}
string s = "this is a string"
%many repetitions
string s = "this is a string"
\end{tcblisting}
答案1
由于给定的代码不可编译,尤其是缺少有关所用样式的信息CSharp
,我无法测试该问题。但是,我对问题的原因有所猜测,因此我尝试给出一个最佳的揣测回答。
当tcolorbox
遇到分页符时,后面的框部分的颜色将恢复为设置值。出现此行为的原因是 (La)TeX 无法在\vsplit
后台运行期间跟踪颜色信息。
默认文本颜色为黑色。我猜你的CSharp
样式将当前文本颜色设置为白色,在换行符后将替换为默认黑色。解决方案是更改的默认文本颜色tcolorbox
。尝试将以下内容添加到你的选项列表中:
%...
colupper=white,
%...
我的猜测这就是诀窍。