简体   繁体   中英

Make LaTeX table caption same width as table?

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}

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)

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.

通过将我的标题放在parbox中我获得了成功:

\parbox{5cm}{\caption{Lorem ipsum dolor sit amet...}}

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM