subfigure 与 subfig 包的兼容性

subfigure 与 subfig 包的兼容性

假设我有如下所示的图像分组。

subfig我的问题是,我想在使用该包的环境中包含这种图像分组,subcaption但两者subfig不能很好地协同工作。因此,我的问题是:如何在环境中复制下面的图像分组subfig--> 例如,如何使用 subfig 包中的 \subfloat 宏获得如下所示的相同结果?

目标实际上是在中间放置一张大图像,并在其周围放置 8 张图片。

\documentclass{article}
\usepackage{caption,subcaption}
\usepackage[demo]{graphicx} % demo is just for the example

\begin{document}
\begin{figure}
\centering

\begin{subfigure}[]{.2\textwidth}
    \includegraphics[width=\textwidth,height=2cm]{x}
    \caption{A short figure}

\end{subfigure}\qquad
\begin{subfigure}[]{.2\textwidth}
    \includegraphics[width=\textwidth,height=2cm]{x}
    \caption{A short figure}
\end{subfigure}\qquad

\begin{subfigure}[]{.2\textwidth}
    \includegraphics[width=\textwidth,height=2cm]{x}
    \caption{A short figure}

    \vspace{2ex}

    \includegraphics[width=\textwidth,height=2cm]{x}
    \caption{A short figure}
\end{subfigure}\qquad
\begin{subfigure}[]{.4\textwidth}
\includegraphics[width=\textwidth,height=5cm]{x}
\caption{A tall figure}
\end{subfigure}\qquad
\begin{subfigure}[]{.2\textwidth}
\includegraphics[width=\textwidth,height=2cm]{x}
\caption{A short figure}

\vspace{2ex}

\includegraphics[width=\textwidth,height=2cm]{x}
\caption{A short figure}
\end{subfigure}\qquad

\begin{subfigure}[]{.2\textwidth}
    \includegraphics[width=\textwidth,height=2cm]{x}
    \caption{A short figure}

\end{subfigure}\qquad
\begin{subfigure}[]{.2\textwidth}
    \includegraphics[width=\textwidth,height=2cm]{x}
    \caption{A short figure}
\end{subfigure}\qquad

\caption{The full caption}
\end{figure}
\end{document}

在此处输入图片描述

答案1

看看以下解决方案是否可以帮助您。

\documentclass{article}
\usepackage{caption}
\usepackage[demo,               % demo is just for the example
            export]{adjustbox}
\usepackage{subfig}
\usepackage{multirow, tabularx}

\begin{document}
    \begin{figure}
\setkeys{Gin}{width=\linewidth, keepaspectratio}

\begin{tabularx}{\linewidth}{@{} *{4}{X} @{}}
    & \subfloat[A short image]{\includegraphics[valign=t]{x}}
        & \subfloat[A short image]{\includegraphics[valign=t]{x}}
            &                                                           \\
\subfloat[A short image]{\includegraphics[valign=t]{x}}
    & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep}X}{
        \multirow[t]{2}{=}{\subfloat[A tall image]{\includegraphics[height=78mm,valign=t]{x}}}
                                                    }
        & \subfloat[A short image]{\includegraphics[valign=t]{x}}       \\
\subfloat[A short image]{\includegraphics[valign=t]{x}}
    &   &   & \subfloat[A short image]{\includegraphics[valign=t]{x}}   \\
    & \subfloat[A short image]{\includegraphics[valign=t]{x}}
        & \subfloat[A short image]{\includegraphics[valign=t]{x}}
            &                                                           \\
\end{tabularx}
\caption{The full caption}
    \end{figure}
\end{document}

在此处输入图片描述

答案2

根据要求,这里是一个\subfloat与子标题兼容的版本。

添加\sufloatbox可能有点过头了,但可以想象,#2可以使用 来包含代码,例如\box0。我注意到\subfloat和都\caption使用\@tempboxa,尽管目的不同。

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{blindtext}

\newsavebox{\subfloatbox}

\newcommand{\subfloat}[2][\empty]% #1 = caption (optional), #2 = image
{\bgroup
  \captionsetup[subfigure]{font=footnotesize}%
  \savebox\subfloatbox{#2}%
  \begin{subfigure}[t]{\wd\subfloatbox}
    \usebox\subfloatbox
    \ifx\empty#1\relax
      \stepcounter{subfigure}%
    \else
      \caption{#1}%
    \fi
  \end{subfigure}%
\egroup}

\begin{document}
\begin{figure}[htp]
\noindent\rlap{\rule{\textwidth}{0.5pt}}% show baseline
\subfloat[]{\includegraphics[scale=0.3]{example-image-a}}\hfill
\subfloat[\blindtext]{\includegraphics[scale=0.3]{example-image-b}}\hfill
\subfloat{\includegraphics[scale=0.3]{example-image-c}}
\end{figure}
\end{document}

这是一个基于的更简单的版本\subfigurebox

\newcommand{\subfloat}[2][\empty]{%
  \ifx\empty#1\relax
    \subcaptionbox*{}{#2}%
    \stepcounter{subfigure}%
  \else
    \subcaptionbox{#1}{#2}%
  \fi}

相关内容