列表下方有名为“keywordstyle keywordstyle”的附加文本

列表下方有名为“keywordstyle keywordstyle”的附加文本

我为 Python 代码定义了以下清单:

\newtcblisting[use counter from=sqlCode, list inside=codes]{pythonCode}[2][]{%
  listing only,
  breakable,
  top=0.25pt,
  bottom=0.25pt,
  right=0.25pt,
  left=0.25pt,
  colback=gray!15!white,
  colframe=gray!50,
  sharp corners,
  boxrule=0pt,
  bottomrule=0pt,
  toprule=1.5pt,
  enhanced jigsaw,
  listing options={ %
    language=Python,
    numbers=left,
    moredelim={[is][keywordstyle]{@}{@}},
    basicstyle=\footnotesize\ttfamily,
    numberstyle=\footnotesize\ttfamily\color{darkgray},
    breaklines=false,
    breakautoindent=false,
    breakindent=0pt,
    stepnumber=1,
    tabsize=3,
    showstringspaces=false,
    breakatwhitespace=false,
    aboveskip=0pt,
    showtabs=false,
    belowskip=0pt,
    backgroundcolor=\color{white},   % choose the background color
    escapechar=¤,
    escapeinside={\¤}{)}
    keywordstyle=\color{blue},       % keyword style
    stringstyle=\color{mymauve},     % string literal style
    commentstyle=\color{mygreen},    % comment style
  },%
  lefttitle=0pt,
  coltitle=black,
  colbacktitle=white,
  title={Listing \thetcbcounter:  #2},#1%  
  borderline north={1.5pt}{14.4pt}{gray!50},
}

然而,不知何故,我在我的列表下方看到了以下文字: 带有附加文本的图像

有谁知道如何解决这个问题,所以我没有添加“keywordstyle keywordstyle”?

我已经尝试解决这个问题一段时间了,但没有任何进展。

答案1

两个问题:

  1. 可选参数#1应该位于声明的末尾newtcblisting,即
title={Listing \thetcbcounter:  #2}, 
  borderline north={1.5pt}{14.4pt}{gray!50},
  #1%
}
  1. escapeinside={\¤}{)}和之间缺少逗号,keywordstyle=\color{blue},导致该单词keywordstyle被打印出来。

完整 MWE:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings, breakable, skins}
\newtcblisting[auto counter, list inside=codes]{pythonCode}[2][]{%
  listing only,
  breakable,
  top=0.25pt,
  bottom=0.25pt,
  right=0.25pt,
  left=0.25pt,
  colback=gray!15!white,
  colframe=gray!50,
  sharp corners,
  boxrule=0pt,
  bottomrule=0pt,
  toprule=1.5pt,
  enhanced jigsaw,
  listing options={ %
    language=Python,
    numbers=left,
    moredelim={[is][keywordstyle]{@}{@}},
    basicstyle=\footnotesize\ttfamily,
    numberstyle=\footnotesize\ttfamily\color{darkgray},
    breaklines=false,
    breakautoindent=false,
    breakindent=0pt,
    stepnumber=1,
    tabsize=3,
    showstringspaces=false,
    breakatwhitespace=false,
    aboveskip=0pt,
    showtabs=false,
    belowskip=0pt,
    backgroundcolor=\color{white},   % choose the background color
    escapechar=¤,
    escapeinside={\¤}{)},
    keywordstyle=\color{blue},       % keyword style
    stringstyle=\color{red},     % string literal style
    commentstyle=\color{green},    % comment style
  },%
  lefttitle=0pt,
  coltitle=black,
  colbacktitle=white,
  title={Listing \thetcbcounter:  #2}, 
  borderline north={1.5pt}{14.4pt}{gray!50},
  #1%
}
\begin{document}
\begin{pythonCode}{Basic List Operations}
>>> my_list = [1,2,3]
>>>
#index()
\end{pythonCode}
\end{document}

结果:

在此处输入图片描述

相关内容