32

It looks bad in my paper if a caption is wider than the table underneath it. How can I make them both align?

Right now my code looks like:

\begin{table}[th!]
\caption{Reference temperature blah blah}
\centering
\begin{tabular}{llll}
...
\end{tabular}
\end{table}
webjunkie
  • 6,891
  • 7
  • 46
  • 43

5 Answers5

40

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

For global effect

\usepackage[width=.75\textwidth]{caption}

For local effect only in current environment:

\usepackage{caption}
\captionsetup{width=.75\textwidth}


More info in caption package doc:

https://www.ctan.org/pkg/caption?lang=en

http://mirrors.ctan.org/macros/latex/contrib/caption/caption-eng.pdf (direct link to PDF subject to change)

Johu
  • 626
  • 7
  • 15
  • 2
    Is there a way to make it so that the caption text is justified, so that the text is flush with the left and right boundaries of the caption? – Nike Nov 04 '16 at 20:19
  • Using this seems to alter alignment. – hola Apr 30 '22 at 23:46
14

if you know or find out the width of the table, let's say 5cm -

  • if you're using a KOMA-Script class:

    \setcapwidth[c]{5cm}

  • if you're using the caption package:

    \captionsetup{width=5cm}

Both may be applied inside the table environment.

An automatically calculating solution is more complicated, but could be done using the \settowidth command.

Stefan
  • 3,550
  • 1
  • 18
  • 18
14

I've had success by putting my caption in a parbox:

\parbox{5cm}{\caption{Lorem ipsum dolor sit amet...}}
lubar
  • 2,589
  • 2
  • 26
  • 28
5

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.

  • 3
    As Hadi recommends, I used the **threeparttable** package to have a table caption as wide as the table. I put the table caption between *\begin{threeparttable}* and *\end{threeparttable}*. – miyashin Aug 28 '13 at 18:05
2

Put your table plus caption inside a minipage. The caption will wrap. This is also a great way to have proper footnotes for tables.

Caleb Hattingh
  • 9,005
  • 2
  • 31
  • 44
  • 1
    I think I might have already tried that... how do I get the minipage to the table width? – webjunkie Jul 23 '10 at 21:59
  • 1
    Search in this page for *Side-by-side tables* (shows an example of specifying minipage width): http://people.csail.mit.edu/jrennie/latex/ – Caleb Hattingh Jul 26 '10 at 14:23