无子图的子标题

无子图的子标题

我正在布局一个文档,其中包含由一系列子图像组成的图像,并且每个图像都直接在图像本身中包含标签。以下是一个例子...

单个 PNG

再次强调,上面不是 6 个单独的 PNG 文件,而是 1 个 PNG。

我需要为图像添加标题...我更愿意使用类似的东西subcaption来保持文档中所有图像的格式一致。

目前,我正在给该图加上这样的标题:

\usepackage{graphicx}
\usepackage[font=footnotesize,
            labelfont=bf, 
            labelsep=endash, 
            justification=RaggedRight]{caption}

\begin{document}

\begin{figure}[ht]
    \includegraphics[width=\linewidth]{fig.png}
    \caption[My Figure]{\textbf{Myfigure (a)} This describes something shown in a. \textbf{(b)} This describes something shown in b. \textbf{(c)} This describes something shown in c. \textbf{(d)} This describes something shown in d. \textbf{(e)} This describes something shown in e. \textbf{(f)} This describes something shown in f.}
    \label{fig:myfig}
\end{figure}

\end{document}

在此处输入图片描述

为了保持代码紧凑并保持格式一致,我更喜欢使用类似subcaption包的东西。语法可能看起来像这样...

\usepackage{graphicx}
\usepackage[font=footnotesize,
            labelfont=bf, 
            labelsep=endash, 
            justification=RaggedRight]{caption}
\usepackage[labelformat=parens,
            labelsep=space]{subcaption}

\begin{document}

\begin{figure}[ht]
    \includegraphics[width=\linewidth]{fig.png}
    \caption[My Figure]{My Figure} \subcaption{This describes something shown in a.} \subcaption{This describes something shown in b.} \subcaption{This describes something shown in c.} \subcaption{This describes something shown in d.} \subcaption{This describes something shown in e.} \subcaption{This describes something shown in f.}
    \label{fig:myfig}
\end{figure}

使用子标题

然而,这有两个问题...

  1. 编译器会抱怨,因为subcaption环境不正确。
  2. 主字幕标题和每个子字幕之间有一个换行符。

有没有什么方法可以实现像第一个例子中那样的标题,但又不必像第一个例子中那样强行实现它?

答案1

子标题文档中的图 5 提供了一个可以根据您的情况进行调整的示例:

\documentclass{article}

\usepackage{graphicx}
\usepackage[font=footnotesize,
            labelfont=bf, 
            labelsep=endash, 
            justification=RaggedRight]{caption}
\usepackage[labelformat=parens,
            labelsep=space]{subcaption}

\begin{document}

\begin{figure}[ht]
    \includegraphics[width=\linewidth]{example-image}
    {
    \phantomsubcaption\label{figa}
    \phantomsubcaption\label{figb}
        \phantomsubcaption\label{figc}
        \phantomsubcaption\label{figd}
        \phantomsubcaption\label{fige}
        \phantomsubcaption\label{figf}
        }
    \caption[My Figure]{My Figure (\subref{figa}) This describes something shown in a. (\subref{figb}) This describes something shown in b. (\subref{figc}) This describes something shown in c.(\subref{figd}) This describes something shown in d.(\subref{fige}) This describes something shown in e.(\subref{figf}) This describes something shown in f.}
    \label{fig:myfig}
\end{figure}

\end{document}

答案2

这用于\mycaption实现第一个示例中的格式。当然,它真正能帮你节省的只是格式化计数器。

您可以放一个\label 里面各有不同\mycaption,如果愿意的话。它们不应该干扰主标题\label

\documentclass{article}
\usepackage{graphicx}
\usepackage[font=footnotesize,
            labelfont=bf, 
            labelsep=endash, 
            justification=RaggedRight]{caption}

\newcounter{subfigure}[figure]% or install subcaption package
\renewcommand{\thesubfigure}{\alph{subfigure}}% format for \ref
\newcommand{\mycaption}[1]% #1 = text
{\bgroup
  \refstepcounter{subfigure}% global counter, local label
  \textbf{(\alph{subfigure})}~#1
 \egroup}


\begin{document}

\begin{figure}[ht]
    \includegraphics[width=\linewidth]{example-image}
    \captionsetup{singlelinecheck=off}% otherwise starts at (g)
    \caption[My Figure]{\textbf{Myfigure} 
      \mycaption{This describes something shown in a.} 
      \mycaption{This describes something shown in b.}
      \mycaption{This describes something shown in c.}
      \mycaption{This describes something shown in d.}
      \mycaption{This describes something shown in e.}
      \mycaption{This describes something shown in f.}}
    \label{fig:myfig}
\end{figure}

\end{document}

演示

相关内容