# How to set a background color for a listing?

Someone who knows how to fill with color only the box?

\begin{shaded}
\begin{lstlisting}

if (a < b)
{
printf("A is smaller than  B!\n");
}
a = b;

\end{lstlisting}

-
listings has a setting backgroundcolor=\color{gray} for this purpose. –  Stephan Lehmke Dec 9 '13 at 20:18
Thank you,works great! –  kostas Dec 9 '13 at 20:22
@StephanLehmke: Maybe convert your comment into an answer? –  Kevin C Dec 10 '13 at 21:19
@KevinC Done. I thought this must be a duplicate of something, but doesn't seem so :-) –  Stephan Lehmke Dec 11 '13 at 4:57
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Jan 13 at 14:33

listings has a setting backgroundcolor=\color{gray} for this purpose:

\lstset{backgroundcolor=\color{gray}}
\begin{lstlisting}

if (a < b)
{
printf("A is smaller than  B!\n");
}
a = b;

\end{lstlisting}


See section 2.7 of the manual which you should get with texdoc listings.

-