# 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}

-
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 '14 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.

-