Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

For my listings, I use this caption setup:

\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white, margin=0pt, font={bf,footnotesize}}

For each listing, pdflatex warns me:

Overfull \hbox (6.0pt too wide) in paragraph at lines 129--129

In the PDF, one can easily see that it is indeed too wide there:

And a close up:

How can I get this to match exactly the width of the remaining contents?

share|improve this question

1 Answer 1

up vote 19 down vote accepted

A \colorbox adds some space before and after the text inside it; this space is \fboxsep wide; so


will do. You might also load the calc package and then write the same in the perhaps more natural syntax

share|improve this answer
Awesome, now it looks really neat! – Martin Ueding Dec 11 '11 at 14:27
Since v3.3 of the caption package the option box=colorbox is available to make things easier. See – Axel Sommerfeldt May 16 '13 at 7:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.