为什么 lstlisting 没有突出显示数字?

为什么 lstlisting 没有突出显示数字?

我想在我的文档中包含一些 Python 代码,以下是我目前所写的内容:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage[spanish]{babel}
\usepackage{listings}
\usepackage{xcolor}

\definecolor{codegreen}{rgb}{0.04314,0.6745,0.07843}
\definecolor{codegray}{rgb}{0.7059,0.6863,0.702}
\definecolor{codered}{rgb}{0.5373,0.02745,0.06275}
\definecolor{codeblue}{rgb}{0.071,0.0258,0.9882}
\definecolor{codepurple}{rgb}{0.6,0.02745,0.5961}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
    commentstyle=\color{codegray},
    keywordstyle=\color{codepurple},
    otherkeywords={range, print, max, len},
    classoffset=1, % starting new class
    keywordstyle=\color{codeblue},
    numberstyle=\color{codered},
    stringstyle=\color{codegreen},
    basicstyle=\ttfamily,
    showspaces=false,                
    showstringspaces=false,
}

\lstset{style=mystyle}

\begin{document}
\begin{lstlisting}[language=Python]
        sd.play(audio.astype('int16'))

        paso = 5
        for i in range(0,ntramas,paso):
    \end{lstlisting}
\end{document}

我希望代码如下所示:

在此处输入图片描述

然而,这是我在乳胶中得到的结果:

在此处输入图片描述

不同之处在于数字的颜色,尽管我已经用numberstyle我希望它们是红色的,但它们显示为黑色。

谢谢您的回答。

相关内容