子浮动标题中有多个对齐的行/段落,如果较短则带有居中线

子浮动标题中有多个对齐的行/段落,如果较短则带有居中线

具有以下 MWE:

\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}
    \begin{figure}
%       \captionsetup[subfigure]{justification=centering}
        \centering
        \begin{subfigure}[t]{0.31\textwidth}
            \includegraphics[width=\textwidth]{example-image-a}
            \caption{\texttt{image 1}}%
            \label{fig:image1}
        \end{subfigure}
        ~%
        \begin{subfigure}[t]{0.31\textwidth}
            \includegraphics[width=\textwidth]{example-image-b}
            \caption[\texttt{image 2}]{\texttt{image 2}\\*
                Longer text containing description of the image contents.}
            \label{fig:image1}
        \end{subfigure}
        ~%
        \begin{subfigure}[t]{0.31\textwidth}
            \includegraphics[width=\textwidth]{example-image-c}
            \caption[\texttt{image 3}]{\texttt{image 3 having a name longer than the other two images}\\*
                Longer text containing description of the image contents.}
            \label{fig:image1}
        \end{subfigure}
    \end{figure}
\end{document}

我想知道是否可以更改子浮点字幕的格式,以便 (b) 的第一行居中(如 (a) 中所示)。通常,如果字幕中定义了多行,则每行如果占的空间少于一行则应居中\linewidth,如果较长则应对齐 - 就像字幕的默认行为一样,但对不同的行分别应用。

在此处输入图片描述

可选地,第二行和后续行不需要为标签缩进,因此它们可以占用其子浮点数的所有宽度。

答案1

也许以下内容会给你想要的结果:

在此处输入图片描述

\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}
    \begin{figure}
       \captionsetup[subfigure]{justification=raggedright,font=tt}
        \centering
        \begin{subfigure}[t]{0.31\textwidth}
            \includegraphics[width=\textwidth]{example-image-a}
            \caption{image 1}%
            \label{fig:image1}
        \end{subfigure}
        ~%
        \begin{subfigure}[t]{0.31\textwidth}
            \includegraphics[width=\textwidth]{example-image-b}
            \caption{image 2}
            Longer text containing description of the image contents.
            \label{fig:image2}
        \end{subfigure}
        ~%
        \begin{subfigure}[t]{0.31\textwidth}
            \includegraphics[width=\textwidth]{example-image-c}
            \caption{image 3 having a name longer than the other two images}
                Longer text containing description of the image contents.
            \label{fig:image3}
        \end{subfigure}
    \end{figure}
\end{document}

相关内容