[Tex/LaTex] How to use format=hang *within* \caption{} which is already set to \captionsetup{format=hang}

captionsindentationparagraphsphantom

I know that \captionsetup{format=hang} will give me a figure caption like this:

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

But how can I have something like this:

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

Best Answer

The following declares a new option addlabel for the caption package to set an additional text for the label and a new caption label format (also addlabel to be used with labelformat), which uses this text. With this a text like Example: can be made part of the label, and hang includes it.

enter image description here

The code:

\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}