TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 tex.stackexchange.com/a/88206/2574 – 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.