可能重复:
Listings 包无法正确显示 PHP 字符串
我正在使用清单来包含 C 代码,但遇到了一个问题:当我在清单中插入printf像下面这样
printf("inc_count(): thread \%ld, count = \%d Threshold reached.\n", a,b);
“ .. ” 内的文本未显示。我还没有找到修复此问题的方法,我认为这应该很简单,也许我只是使用了错误的关键字... 你能帮助我吗?
编辑:用法示例:
\begin{lstlisting}[language=C, label=cond-var, caption="Condition variables usage example"]
printf("inc_count(): thread \%ld, count = \%d Threshold reached.\n",
my_id, count);
\end{lstlisting}
显示的内容如下
答案1
鉴于您的代码之前在 @wh1t3 中运行良好,这表明您的文档中的其他内容存在问题。我猜您的列表选项将字符串样式设置为白色背景上的白色文本,您确认这是真的。供将来参考的示例(还更正了标题周围的多余引号和字符串中的反斜杠):
\documentclass{article}
\usepackage{xcolor,listings}
\lstset{basicstyle=\scriptsize,stringstyle=\color{white},language=C}
\begin{document}
\begin{lstlisting}[label=cond-var-white, caption={Condition variables usage example}]
printf("inc_count(): thread %ld, count = %d Threshold reached.\n",
my_id, count);
\end{lstlisting}
\lstset{backgroundcolor=\color{gray!50}}
\begin{lstlisting}[label=cond-var-gray, caption={Condition variables usage example}]
printf("inc_count(): thread %ld, count = %d Threshold reached.\n",
my_id, count);
\end{lstlisting}
\lstset{backgroundcolor=\color{white},stringstyle=\color{black}}
\begin{lstlisting}[label=cond-var-black, caption={Condition variables usage example}]
printf("inc_count(): thread %ld, count = %d Threshold reached.\n",
my_id, count);
\end{lstlisting}
\end{document}