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

We have table caption background image. We put this as image. But we need the table caption and images exactly same width as table body.

share|improve this question
hmmm. a little more detail would help. you have a table, a caption and an image....what do you want to do with each? put the image as the caption? put the image as background to the caption? – Yossi Farjoun Dec 17 '10 at 11:01
Put the table first in a box then you its width and height. – Herbert Dec 17 '10 at 16:01

For customizing captions, the caption packages is highly recommendable. Besides a lot of other features, you can also adjust the width of captions, for example:


You may use this command globally in your preamble but also within a table environment, which keeps it local and thus limits the effect of this setting.

With a KOMA-Script class, without the caption package, you could use \setcapwidth:


Since you use a background image, you might know the necessary width. Even if you don't know it, the width for the caption could be automatically calculated from the width of the table or image. Then the command \settowidth comes handy`.

  • create a macro for the width: \newlength{\cwidth}

  • get the width of the object: \settowidth{\cwidth}{object}

  • set the caption widht by one of the two commands at the beginning of this answer

  • print out the object

You could even write a macro for automatizing that, like


This works well with images. Tables might be harder as object, but in your case you could refer to your background images.

share|improve this answer
Great approach (don't know why OP did not accept). However, getting the width of an object might be easy if your object is an imported file (png etc.). But when it comes to a pgfplot-generated object, how do you retrieve its dimensions? (Since some pgfplots needs a lot of code-lines it would be rather strange to insert the same code again into autowidth as its argument) – John Nov 9 '12 at 18:23
One further idea is, to use \captionsetup[table]{width=6cm} to just change the caption with for tableenvironments. – Ronny Dec 17 '12 at 8:42

Another option would be using the threeparttable or ctable packages, which will fit the width of the caption to the width of the table automatically.

share|improve this answer

in caption package guide:

Only fixed widths are supported here; if you are looking for a way to limit the width of the caption to the width of the figure or table, please take a look at the floatrow[8] or threeparttable[22] package.

share|improve this answer

Actually there ise more legal way to do this using captions package option width.

For global effect


For local effect only in current environment:


More info in caption package doc:


share|improve this answer
But this makes the caption width conform to the text block, not the table-specific width. – Werner May 9 '12 at 17:39
@Werner yeah... you are right. I was just carried away as it was good enough for me. – Johu May 9 '12 at 17:45

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.