[Tex/LaTex] Table caption Width

captionsfloatstableswidth

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.

Best Answer

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:

\captionsetup{width=6cm}

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:

\setcapwidth[c]{6cm}

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

\newcommand{\autowidth}[1]{%
  \settowidth{\cwidth}{#1}%
  \captionsetup{width=\cwidth}%
  #1%
}

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

Related Question