当我尝试使用包在我的文档中显示控制台输出时遇到问题lstlisting
。它显示了多余的单引号,如下图第一行所示:
此代码重现了该问题(至少对我来说)。我需要帮助来摆脱它们。
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{white},
basicstyle={\footnotesize\color{black},\fontfamily{cmtt}\selectfont,\bfseries},
stringstyle=\color{black},
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2,
}
\lstset{style=mystyle}
\begin{document}
\lstset{escapeinside={<@}{@>}}
\begin{lstlisting}
traceroute to upm.es (138.100.200.6), 30 hops max, 60 byte packets
1 192.168.1.1 (192.168.1.1) <@\textcolor{red}{[*]}@> 1.600 ms 3.262 ms 3.260 ms
2 10.233.128.1 (10.233.128.1) <@\textcolor{red}{[*]}@> 8.496 ms 13.889 ms 13.911 ms
3 10.239.240.113 (10.239.240.113) <@\textcolor{red}{[*]}@> 13.945 ms 14.828 ms 17.957 ms
4 10.254.14.1 (10.254.14.1) <@\textcolor{red}{[*]}@> 27.655 ms 28.202 ms 29.326 ms
5 10.239.240.181 (10.239.240.181) <@\textcolor{red}{[*]}@> 32.501 ms 10.254.13.201 (10.254.13.201) <@\textcolor{red}{[*]}@> 33.297 ms 33.321 ms
6 10.254.13.237 (10.254.13.237) <@\textcolor{red}{[*]}@> 29.209 ms 10.254.2.137 (10.254.2.137) <@\textcolor{red}{[*]}@> 19.383 ms 10.254.2.145 (10.254.2.145) <@\textcolor{red}{[*]}@> 17.886 ms
7 10.254.3.226 (10.254.3.226) <@\textcolor{red}{[*]}@> 20.164 ms 17.590 ms 10.254.14.106 (10.254.14.106) <@\textcolor{red}{[*]}@> 54.655 ms
8 rediris.baja.espanix.net (193.149.1.26) <@\textcolor{green}{[AS6895]}@> 22.132 ms 22.362 ms rediris.alta.espanix.net (193.149.1.154) <@\textcolor{green}{[AS6895]}@> 22.240 ms
9 redimadrid-cieamt-router.rediris.es (130.206.212.106) <@\textcolor{blue}{[AS766]}@> 18.079 ms 21.496 ms *
10 * upm-ciemat.net.redimadrid.es (193.145.14.133) <@\textcolor{blue}{[AS766]}@> 55.954 ms *
11 www.upm.es (138.100.200.6) <@\textcolor{blue}{[AS766]}@> 20.736 ms 20.866 ms 19.413 ms\end{lstlisting}
\end{document}
答案1
其实它们是逗号。罪魁祸首是
basicstyle={\footnotesize\color{black},\fontfamily{cmtt}\selectfont,\bfseries},
应该是
basicstyle=\ttfamily\footnotesize,
您必须合并所有字体声明,而不是给出声明列表。
请注意,对于没有粗体字样的\bfseries
家族,这不会执行任何操作。这似乎也是多余的。cmtt
\color{black}