分頁符號處的 tcblisting 問題

分頁符號處的 tcblisting 問題

我使用 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 的修復。如果有人有興趣的話。

\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樣式將當前文字顏色設為白色,並在中斷後替換為預設的黑色。解決方案是更改 .txt 檔案的預設文字顏色tcolorbox。嘗試將以下內容新增到您的選項清單中:

%...
colupper=white,
%...

我的猜測就是這可以解決問題。

相關內容