子浮动:标签在旁边,标题在下方

子浮动:标签在旁边,标题在下方

我正在寻找一种可能性,将子图的标签 (a)、(b)、(c)... 放在子图旁边,并在下面放置标题。所以我尝试了 sidesubfigure (Subfig标签定位),它完全按照我想要的方式放置标签,但是我没有找到将标题放在图像下方的解决方案。

\documentclass{article}
    \usepackage{floatrow}
    \usepackage{subfig}
    \usepackage{caption}
    \usepackage{rule}

\begin{document}

\begin{figure}
\sidesubfloat[description]{\rule{2cm}{2cm}}
\hfill
\sidesubfloat[description]{\rule{2cm}{2cm}}
\end{figure}

\end{document}

有可能这么做吗?

在此处输入图片描述

编辑:刚刚遇到另一个问题,当我像这样在两行中添加 4 张相同大小的图片时,图片会发生移动:

\begin{figure}[H]
    \begin{mysubfigure}{desc}{imageA}
        \includegraphics[width=4cm, height=4cm]{imageA}
    \end{mysubfigure}
    \hfill
    \begin{mysubfigure}{shorter desc}{imageB}
        \includegraphics[width=4cm, height=4cm]{imageB}
    \end{mysubfigure}
    \newline
        \begin{mysubfigure}{desc}{imageC}
        \includegraphics[width=4cm, height=4cm]{imageC}
    \end{mysubfigure}
    \hfill
    \begin{mysubfigure}{shorter desc}{imageD}
        \includegraphics[width=4cm, height=4cm]{imageD}
    \end{mysubfigure}
\caption{Two images: \subref{imageA} is imageA, \subref{imageB} is imageB}
\end{figure}

在此处输入图片描述

答案1

stackengine这是使用(和)包的解决方案varwidth

在此处输入图片描述

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{subcaption}
\usepackage{varwidth}
\usepackage{stackengine}

\usepackage{lipsum}
\usepackage{float}

\DeclareCaptionLabelFormat{none}{}
\captionsetup[subfigure]{justification=centering, labelformat=none}

\newsavebox{\mybox}
\newlength{\mylength}

\makeatletter
\newenvironment{mysubfigure}[2]{%
    \def\arg@caption{#1}%
    \def\arg@label{#2}%
    \def\arg@ref{(\subref{\arg@label})}%
    \sbox{\mybox}{\begin{varwidth}{\linewidth}{\arg@ref}\end{varwidth}}%
    \edef\arg@reflen{\the\wd\mybox}%
    \edef\arg@refline{\the\dimexpr\ht\mybox+\dp\mybox}%
    \begin{lrbox}{\mybox}%
    \begin{varwidth}{\linewidth}%
}{%
    \end{varwidth}%
    \end{lrbox}%
    \setlength{\mylength}{\the\dimexpr\ht\mybox+\dp\mybox-\arg@refline}%
    \setlength{\mylength}{0.5\mylength}%
    \hspace{\arg@reflen}\subfigure[b]{\the\wd\mybox}%
        \centering%
        \toplap[\mylength]{l}{\arg@ref}\usebox{\mybox}%
        \caption{\arg@caption\label{\arg@label}}%
    \endsubfigure%
}
\makeatother

\begin{document}

\lipsum[1]

\begin{figure}[H]
    \centering
    \begin{mysubfigure}{longer description than the other}{imageA}
        \includegraphics[width=3cm, height=6cm]{imageA}
    \end{mysubfigure}
    \begin{mysubfigure}{shorter desc}{imageB}
        \includegraphics[width=4cm, height=3cm]{imageB}
    \end{mysubfigure}
\caption{Two images: \subref{imageA} is imageA, \subref{imageB} is imageB}
\end{figure}

\lipsum[2]

\end{document}

相关内容