如何在已经设置为 \captionsetup{format=hang} 的 \caption{} 内使用 format=hang?

如何在已经设置为 \captionsetup{format=hang} 的 \caption{} 内使用 format=hang?

我知道这\captionsetup{format=hang}会给我一个像这样的图形标题:

Figure 1.3: Example: This is an example that is shown here. Look at the details of this
            picture!

但是我怎么会有这样的事情:

Figure 1.3: Example: This is an example that is shown here. Look at the details of this
                     picture!

答案1

下面声明了包addlabel的一个新选项caption,用于为标签设置附加文本和使用此文本的新标题标签格式(也addlabel与 一起使用labelformat)。这样,文本如下例子:可以作为标签的一部分,并将hang其包含在内。

在此处输入图片描述

代码:

\documentclass{article}
\usepackage{graphicx}   
\usepackage{caption}                

\makeatletter
% command from caption.sty
\DeclareCaptionOption{addlabel}{\def\caption@addlabel{#1}}
% new format
\DeclareCaptionLabelFormat{addlabel}{#1~#2:~\caption@addlabel}
\makeatother

\captionsetup{%
    labelformat=addlabel,
    addlabel={Example},   % additional label text
    format=hang
}

\begin{document}

\begin{figure}[htbp]
    \centering
    \includegraphics[height=2cm]{example-image}
    \caption{A very long caption text, which needs more than one line. Just some more text to fill it.}
\end{figure}

\begin{figure}[htbp]
    \centering
    \includegraphics[height=2cm]{example-image}
    % additional label text set locally
    \captionsetup{addlabel={Result}}
    \caption{A very long caption text, which needs more than one line. Just some more text to fill it.}
\end{figure}

\begin{figure}[htbp]
    \centering
    \includegraphics[height=2cm]{example-image}
    \caption{A very long caption text, which needs more than one line. Just some more text to fill it.}
\end{figure}

\end{document}

相关内容