The caption package
Changes the look of figure and table captions with \captionsetup and adds \caption* and \captionof.
Loading the package
\usepackage{caption}The standard classes fix the caption layout: text in normal size, the label "Figure 1:" in normal weight, a short caption centred. caption turns each of these into an option: font size, bold label, separator, alignment, width and the distance to the figure.
Options go into \usepackage[...]{caption} or into \captionsetup{...}. \captionsetup[table]{...} applies to one float type, and \captionsetup inside a float applies to that float only.
\captionof{figure}{...} writes a numbered caption outside a float, for example in a minipage or a center environment.
Main commands
\captionsetup{font=small, labelfont=bf} | Small caption text with a bold label, for all captions that follow. |
labelsep=period | Period instead of the colon after the number: "Figure 1." |
justification=raggedright, singlelinecheck=false | Left-aligned captions, including those that fit on one line. |
format=hang | Indents the second and later lines to the start of the caption text. |
\captionsetup[table]{skip=6pt} | Options for one float type, here the distance between caption and table. |
\caption*{Source: own measurement.} | Caption without label and number, and without an entry in the list of figures. |
\captionof{figure}{...} | Numbered caption outside a figure environment. |
Complete example
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\captionsetup{font=small, labelfont=bf, labelsep=period}
\begin{document}
\begin{figure}[ht]
\centering
\includegraphics[width=0.4\textwidth]{image.png}
\caption{A caption in small type with a bold label.}
\caption*{Source: own measurement.}
\end{figure}
\begin{center}
\includegraphics[width=0.3\textwidth]{image-a.png}
\captionof{figure}{A numbered caption without a float.}
\end{center}
\end{document}Compiled with pdfLaTeX from TeX Live 2023.
Pitfalls
\captionoutside a float gives \caption outside float.\captionof{figure}{...}is the command for that place.- An image with
\captionofdoes not float, so it can end up in a different order than the floating figures around it. Keep image and caption together in aminipageorcenter, or a page break can separate them. - In the standard classes a caption that fits on one line is centred, whatever
justificationsays.singlelinecheck=falseswitches that off.
Related pages
- How-to Figure caption and label in LaTeX
- How-to Table caption and label in LaTeX
- Package
subcaption - Package
float - Error \caption outside float