[Tex/LaTex] Figure caption alignment screwed when using line break

captionsfloatshorizontal alignmentline-breaking

I am having trouble with figure captions when I need a manual line break.

\documentclass[A4]{book}
\usepackage{subfig}
\usepackage[top=35mm, bottom=38mm, inner=40mm, outer=24mm]{geometry}
\usepackage[hang,small,it]{caption}
\usepackage{showframe}
\begin{document}

\begin{figure}
\centering
\caption{Single line no problem.}
\end{figure}

\begin{figure}
\centering
\caption[Content]{Sketching out variants for a new glass plate based installation.\\%
Unless specified, sizes are in cm.}
\label{fig:sketches_plate_arrangements}
\end{figure}

\end{document}

The second figure caption is left aligned instead of centered. (in my actual setup it is a bit more to the right, and the second line is at least properly indented, but still the caption is way too much left).

enter image description here


Well, since you closed the question for unknown reasons, here is my answer. The idea is to use the margin parameter of captionsetup. If captionsetup is used without "float type" option and inside the \begin{figure} ... \end{figure} block, it only applies the settings for one particular occurrence.

\documentclass[A4]{book}
\usepackage[top=35mm, bottom=38mm, inner=40mm, outer=24mm]{geometry}
\usepackage[hang,small,it]{caption}
\usepackage{subfig}
\usepackage{showframe}
\usepackage{tikz}

\begin{document}

\begin{figure}
\includegraphics[scale=0.2]{dissem_Modell2_hires.png}
\captionsetup{%  settings just for this caption
  margin = 70pt
}
\caption[Content]{Sketching out variants for a new glass plate based installation.%
Unless specified, sizes are in cm.}
\end{figure}

\end{document}

enter image description here

Best Answer

If you don't mind manual tweaks, you can use \oalign:

\documentclass[a4paper]{book}
\usepackage{subfig}
\usepackage[top=35mm, bottom=38mm, inner=40mm, outer=24mm]{geometry}
\usepackage{showframe}
\usepackage{mathtools}
\begin{document}

\begin{figure}
\centering
\caption{Single line no problem.}
\end{figure}

\begin{figure}
\centering
\caption[Content]{\oalign{Sketching out variants for a new glass plate based installation.\hfil\strut\cr\strut Unless specified, sizes are in cm.\hfil}}
\label{fig:sketches_plate_arrangements}
\end{figure}

\end{document}