使用 subcaption 包时间距不同

使用 subcaption 包时间距不同

当我使用 subcaption 包时,如果设置以下跳过选项,标题与最后一个子标题之间的间距很大,如果我不使用以下跳过选项,子标题与下一张图片之间的间距很近。

有没有办法让系统判断标题上方是否有子标题,如果有,则禁用跳过标题包中的选项,否则可以吗?

在此处输入图片描述

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage[font={small}, justification=centering]{caption}
\captionsetup[figure]{position=bottom,skip=25pt}

\usepackage[labelformat=simple]{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}
\captionsetup[subfigure]{position=below,skip=0pt,belowskip=5pt}
\usepackage{lipsum}

\begin{document}
    
    \lipsum[1]
    
    \begin{figure}[!htbp]
        \subcaptionbox{heading}{\includegraphics[width=0.49\linewidth]{imagefile}}%
        \hfill
        \subcaptionbox{heading}{\includegraphics[width=0.49\linewidth]{imagefile}}      
        \subcaptionbox{heading}{\includegraphics[width=0.49\linewidth]{imagefile}}%
        \hfill
        \subcaptionbox{heading}{\includegraphics[width=0.49\linewidth]{imagefile}}
        
        \caption{text text text text text text text text text text text text text} 
    \end{figure}
    
    \lipsum[1]
    
    
    \begin{figure}[!htbp]
        \centering
        \includegraphics[width=0.49\linewidth]{imagefile}       
        \caption{text text text text text text text text text text text text text} 
    \end{figure}

    \lipsum[1]
    
\end{document}

答案1

belowskip总是添加。

我建议将其设置为零并在行之间手动添加垂直空间。

\documentclass{article}

\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\captionsetup{
  font=small,
  justification=centering
}
\captionsetup[figure]{
  position=bottom,
%  skip=25pt
}
\captionsetup[subfigure]{
  labelformat=simple,
  position=below,
  aboveskip=3pt
}
\renewcommand\thesubfigure{(\alph{subfigure})}

\begin{document}

\begin{figure}[!htbp]

\subcaptionbox{heading}{\includegraphics[width=0.49\linewidth]{example-image}}%
\hfill
\subcaptionbox{heading}{\includegraphics[width=0.49\linewidth]{example-image}}

\vspace{2ex}

\subcaptionbox{heading}{\includegraphics[width=0.49\linewidth]{example-image}}%
\hfill
\subcaptionbox{heading}{\includegraphics[width=0.49\linewidth]{example-image}}

\caption{text text text text text text text text text text text text text} 
\end{figure}

\begin{figure}[!htbp]

\centering
\includegraphics[width=0.49\linewidth]{example-image}   
\caption{text text text text text text text text text text text text text} 

\end{figure}

\end{document}

在此处输入图片描述

相关内容