有人知道如何仅用颜色填充框吗?
\begin{shaded}
\begin{lstlisting}
if (a < b)
{
printf("A is smaller than B!\n");
}
a = b;
\end{lstlisting}
\end{shaded}
答案1
listings
有一个用于此目的的设置backgroundcolor=\color{gray}
:
\lstset{backgroundcolor=\color{gray}}
\begin{lstlisting}
if (a < b)
{
printf("A is smaller than B!\n");
}
a = b;
\end{lstlisting}
请参阅随附手册的第 2.7 节texdoc listings
。