当我需要手动换行时,图形标题就出现了问题。
\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}
第二个图标题是左对齐而不是居中。(在我的实际设置中,它稍微靠右一些,并且第二行至少正确缩进,但标题仍然太靠左了)。
好吧,既然你出于未知原因关闭了这个问题,下面就是我的答案。这个想法是使用margin
的参数captionsetup
。如果captionsetup
在没有“浮点类型”选项的情况下在块内使用\begin{figure} ... \end{figure}
,它只会应用一次特定事件的设置。
\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}
答案1
如果您不介意手动调整,您可以使用\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}
答案2
您可以利用varwidth
:
\documentclass[a4paper]{book}
\usepackage[top=35mm, bottom=38mm, inner=40mm, outer=24mm]{geometry}
\usepackage{showframe}
\usepackage{varwidth,calc}
\usepackage[hang,small]{caption}
\makeatletter
\newcommand{\breakcaption}{\@dblarg\emit@breakcaption}
\long\def\emit@breakcaption[#1]#2{%
\expandafter\caption\expandafter[\expandafter\emit@removeafter#1\\\@nil]{%
\begin{varwidth}[t]{\textwidth-\widthof{\figurename\space\thefigure:\space}}
#2
\end{varwidth}%
}%
}
\def\emit@removeafter#1\\#2\@nil{#1}
\makeatother
\begin{document}
\begin{figure}
\centering
\breakcaption{Single line no problem.}
\end{figure}
\begin{figure}
\centering
\breakcaption[Short caption]{%
Sketching out variants for a new glass plate based installation.\\
Unless specified, sizes are in cm.}
\end{figure}
\begin{figure}
\centering
\breakcaption{%
Sketching out variants for a new glass plate based installation.
Something else to fill more lines\\
Unless specified, sizes are in cm.}
\label{fig:sketches_plate_arrangements}
\end{figure}
\end{document}
如您所见,您可以在所有情况\breakcaption
下使用它作为替代\caption
,也可以使用可选参数(\\
甚至可以使用 where,但它将与后面的所有内容一起被删除)。我假设在图形列表中您不想要强制中断后的文本,因为它仅在实际标题中才有意义。