我想让“adriano@ubuntu:~$”以蓝色显示,但我不知道为什么这不起作用。我修改了示例这里。
以下是我的想法:
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstset{
backgroundcolor=\color{gray!10}, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}; should come as last argument
basicstyle=\footnotesize, % the size of the fonts that are used for the code
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
breaklines=true, % sets automatic line breaking
captionpos=b, % sets the caption-position to bottom
commentstyle=\color{green}, % comment style
escapeinside={\%*}{*)}, % if you want to add LaTeX within your code
extendedchars=true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
keepspaces=false, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
keywordstyle=\color{blue}, % keyword style
language=bash, % the language of the code
morekeywords={adriano@ubuntu:~}, % if you want to add more keywords to the set
numbersep=5pt, % how far the line-numbers are from the code
showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
showstringspaces=false, % underline spaces within strings only
showtabs=false, % show tabs within strings adding particular underscores
stepnumber=2, % the step between two line-numbers. If it's 1, each line will be numbered
stringstyle=\color{red}, % string literal style
tabsize=2, % sets default tabsize to 2 spaces
title=\lstname % show the filename of files included with \lstinputlisting; also try caption instead of title
}
\begin{document}
\begin{lstlisting}[language=bash, title=Example]
adriano@ubuntu:~$ openssl req -newkey rsa:2048 -nodes -keyout dnsdist.key -x509 -days 365 -out dnsdist.pem #test
\end{lstlisting}
\end{document}
这给了我结果: 顺便说一句,我还会为我的代码添加数字,例如,不仅仅是示例,还显示代码 xx 示例(就像该部分一样)。
谢谢你的帮助,