子图环境 - 如何在每个图形上方写标题?

子图环境 - 如何在每个图形上方写标题?

我有一组 13 个图形。我在子图环境中每行显示 4 个。

我的代码:

\usepackage{floatrow}
\floatsetup[figure]{subcapbesideposition=top}
\usepackage{graphicx}
\usepackage[label font=bf, 
            labelformat=simple]{subfig}
 \captionsetup[subfigure]{labelfont=rm}
\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
\renewcommand\thesubfigure{(\alph{subfigure})}

\begin{document}

    \begin{figure}[H]
    \centering
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}} 
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}} 
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \hfill
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \hfill
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}
    \hfill
    \subfloat[]{\includegraphics[width=0.24\textwidth]{path to fig}}


\end{figure}

\end{document}

这将产生每个图形下方的标题,如下图所示:

生成的字幕

但是,我想在每个图形上方打印标题,并为它们命名,而不是(a)、(b)等...另外,我需要减少一行中每个图形之间的间距。

答案1

将参数添加position=top\captionsetup命令。

以下内容也已更新,以将请求包含在注释中:水平均匀分布图形并命名而不编号。查看代码中的注释以了解哪个命令负责什么。

\documentclass{report}

\usepackage{floatrow}
\usepackage{graphicx}
\usepackage[labelformat=simple]{subfig}

% The following sets the label position to be above the figure
\captionsetup[subfigure]{position=top}

% The following disables numbering of labels (i.e., (a), (1), etc).
\renewcommand\thesubfigure{}

\begin{document}
    
    \begin{figure}[H]
        \centering
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}}
        \hfill % <-- spreads out figure evenly horrizontally
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}} 
        \hfill
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}}
        \hfill
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}}
        \\ % <-- puts a manual line break
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}}
        \hfill
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}} 
        \hfill
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}}
        \hfill
        \subfloat[your name]{\includegraphics[width=0.24\textwidth]{figure.png}}
    \end{figure}

\end{document}

在此处输入图片描述

答案2

您可以将图像组织在表格中,在奇数行插入图像描述(“标题”),在偶数行插入图像。例如,通过使用tabularray表格包,代码为:

\documentclass{report}
\usepackage{graphicx}
\usepackage{tabularray}

\begin{document}
    \begin{figure}[ht]
    \setkeys{Gin}{width=\linewidth}
\begin{tblr}{colsep=2pt,
             colspec={@{} *{4}{X[c]} @{}},
             row{even}={belowsep=1ex},
             row{odd}={rowsep=1 pt}
             }
image name   & image name & image name & image name                     \\
\includegraphics{example-image-duck}
            & \includegraphics{example-image-duck}
                        & \includegraphics{example-image-duck}
                                    & \includegraphics{example-image-duck}  \\
image name   & image name & image name & image name                     \\
\includegraphics{example-image-duck}
            & \includegraphics{example-image-duck}
                        & \includegraphics{example-image-duck}
                                    & \includegraphics{example-image-duck}  \\
image name   & image name & image name & image name                     \\
\includegraphics{example-image-duck}
            & \includegraphics{example-image-duck}
                        & \includegraphics{example-image-duck}
                                    & \includegraphics{example-image-duck}  \\
image name   & image name & image name & image name                     \\
\includegraphics{example-image-duck}
            & \includegraphics{example-image-duck}
                        & \includegraphics{example-image-duck}
                                    & \includegraphics{example-image-duck}  \\
 \end{tblr}
   \end{figure}
\end{document}

在此处输入图片描述

答案3

由于您实际上不需要\subfloat,您只需在顶部对齐的小页面中排版对象即可(前提是描述不超过图像宽度)。

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\begin{figure}[htp]
\centering

\newcommand{\namedimage}[2]{%
  \begin{minipage}[t]{0.24\textwidth}
  \centering #1 \par\smallskip \includegraphics[width=\textwidth]{#2}
  \end{minipage}%
}
\newcommand{\inset}{\hspace{0.012\textwidth}}

\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\par\medskip

\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\par\medskip

\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\inset
\namedimage{desc}{example-image}\par\medskip

\namedimage{desc}{example-image}

\end{figure}

\end{document}

在此处输入图片描述

我本地定义了\namedimage\inset以便于输入。

相关内容