Tx · LaTeX & TikZ

How to Make LaTeX Captions Ragged Right

Published By the 9to5Science editorial team

At a glance

  1. 1. Load the package

    Add the caption package to your document preamble.

  2. 2. Set justification

    Use caption’s justification=raggedright option instead of applying \raggedright directly.

  3. 3. Check single lines

    Set singlelinecheck=false if one-line captions should also be ragged right.

  4. 4. Choose the scope

    Apply the settings globally, to figures or tables, or to one caption.

To make figure or table captions ragged right, configure their justification with the caption package. This is more reliable than putting \raggedright immediately before \caption, because the package has a setting specifically for caption alignment.

If you want even a one-line caption to start at the left edge, turn off the package’s single-line centering check as well.

A minimal example

The following example makes all captions ragged right, including captions that fit on one line:

\documentclass{article}
\usepackage{caption}
\captionsetup{
  justification=raggedright,
  singlelinecheck=false
}

\begin{document}

\begin{figure}[ht]
  \centering
  \rule{4cm}{2cm}
  \caption{A short caption.}
  \label{fig:example}
\end{figure}

\end{document}

The caption package provides the \captionsetup command. The justification=raggedright option sets left-aligned, uneven right edges for multi-line captions. The singlelinecheck=false option prevents the package’s usual special treatment of captions that occupy only one line. The figure itself remains centered because \centering applies to the figure contents; caption alignment is configured separately.

Apply the setting only where needed

You do not have to change every caption in the document. Add an optional type to \captionsetup to target figures or tables:

\captionsetup[figure]{
  justification=raggedright,
  singlelinecheck=false
}

Use [table] instead of [figure] to target table captions. To set both types, use an unqualified \captionsetup{...} as in the example above.

For a single caption, place the setup within the float before \caption:

\begin{figure}[ht]
  \centering
  \rule{4cm}{2cm}
  \captionsetup{justification=raggedright,singlelinecheck=false}
  \caption{A caption with alignment different from the document default.}
\end{figure}

This local setup is intended for that caption rather than for the rest of the document. If you use the same local options repeatedly, a figure- or table-specific setup is easier to maintain.

Why \raggedright can be confusing

In ordinary text, \raggedright is a declaration that changes paragraph formatting. A caption, however, is formatted by LaTeX’s caption mechanism, which may measure it and apply its own alignment rules. As a result, simply writing \raggedright near \caption can be unclear or fail to produce the alignment you expect—especially for captions that fit on one line.

The caption package’s justification option states the intended caption layout directly. Its singlelinecheck option controls a separate behavior: whether short, one-line captions receive special alignment. That is why setting only justification=raggedright may still leave a short caption centered.

Common mistakes

  • Forgetting singlelinecheck=false. The result can look correct for a long, wrapped caption but remain centered for a short one.
  • Putting \centering before \caption and assuming it controls caption text. It controls the float’s contents; use caption settings to choose the caption’s justification.
  • Using \raggedright as a substitute for caption settings. Prefer justification=raggedright when configuring captions through the caption package.
  • Applying the setting too broadly. Use \captionsetup[figure]{...} or [table] if only one kind of caption should change.

The caption package changes caption formatting and may interact with document classes that define their own caption styles. If your class warns about incompatibility or overrides the formatting, check its documentation for its supported caption interface before changing package order or class settings.

References

  1. The caption package — CTAN

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.