0

当使用 lstlisting 和某些参数时,(大多数)代码变成蓝色,即使它应该只是关键字和标识符,而其余的应该是黑色。为了更好地衡量,文档中的其余文本是黑色的:-)

最好关键字也应该是粗体,但我发现这可能是字体问题,但我不知道如何在不更改整个文档的字体的情况下更改 lstlisting 字体。

谢谢你的时间!

\lstset{language={[Sharp]C},
basicstyle=\color{black}\ttfamily\scriptsize,
numbers=left,
numberstyle=\tiny,
numbersep=3pt,
tabsize=1,
extendedchars=true,
breaklines=true,
keepspaces=true,
showspaces=false,
showtabs=false,
xleftmargin=5pt,
framexleftmargin=5pt,
framexrightmargin=5pt,
framexbottommargin=4pt,

morecomment=[l]{//}, %use comment-line-style!
morecomment=[s]{/*}{*/}, %for multiline comments
showstringspaces=false,
commentstyle=\color{black},
keywordstyle=\color{blue}\bfseries,
identifierstyle=\color{blue}\bfseries,
backgroundcolor=\color{almostwhite},
}

以下是已编译 PDF 中的代码示例:

蓝色代码

4

1 回答 1

1

我不知道问题是否已解决,但似乎您的语言 C Sharp 未知是此处的预定义语言p.12 选项卡 1。

lstdefinelanguage您可以使用see here创建自己的语言,以 获取其工作原理的示例

于 2018-11-05T12:30:59.750 回答