# Stylized Caption with Listings [closed]

I'm currently trying to give my listings nice captions, so I decided to use something like this :

``````    \DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{%
\parbox{\textwidth}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}\vskip-4pt}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
``````

Which gives nice results. However, I would like the gray box not to be displayed when I don't specify a caption for a listing, which is not currently the case. I have a big ugly empty rectangle... Do you have any idea how I could achieve this ?

-
Instead of just code snippets, please provide a complete, minimal document illustrating the problem. – Gonzalo Medina Aug 9 '12 at 16:58
With no MWE, this is 'too localized'. Request reopening if more data is available. – Joseph Wright Sep 2 '12 at 13:29

## closed as too localized by Joseph Wright♦Sep 2 '12 at 13:28

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.