自动子字幕列表

自动子字幕列表

想象一下下图

\begin{figure}[H]
\begin{minipage}{0.45\linewidth}
\begin{subfigure}[b]{\textwidth}
\centering
        \includegraphics[width=.7\linewidth]{example-image}
        \caption{}
        \label{fig1a}
    \end{subfigure}
    \quad
    \begin{subfigure}[b]{\textwidth}
    \centering
        \includegraphics[width=.7\linewidth]{example-image}
        \caption{}
        \label{fig1b}
    \end{subfigure}
\end{minipage}%
\begin{minipage}{0.55\linewidth}
    \begin{subfigure}[b]{0.5\textwidth}
    \centering
        \includegraphics[width=\linewidth]{example-image}
        \caption{}
        \label{fig1c}
    \end{subfigure}%
    \begin{subfigure}[b]{0.5\textwidth}
    \centering
        \includegraphics[width=\linewidth]{example-image}
        \caption{}
        \label{fig1d}
    \end{subfigure}
    \quad
    \begin{subfigure}[b]{0.5\textwidth}
    \centering
        \includegraphics[width=\linewidth]{example-image}
        \caption{}
        \label{fig1e}
    \end{subfigure}%
    \begin{subfigure}[b]{0.5\textwidth}
    \centering
        \includegraphics[width=\linewidth]{example-image}
        \caption{}
        \label{fig1f}
    \end{subfigure}
\end{minipage}
\caption{(a) A caption. (b) Another caption. (c) Yet another caption. (d) So many captions. (e) Really. (f) I'm done with captions.} 
\label{fig1}
\end{figure}

这使

在此处输入图片描述

我的问题:是否可以自动标记子图,以便我不需要在图形标题上手写(a),(b),...(f),并保持它们的顺序(由小页面设置)?

从某种意义上说,简单地在每个子图下写上标题就好了,但要让这些标题出现,自动按正确顺序标记,位于图表的主标题中。有什么想法吗?

编辑:我看见这个问题,但还是没有解决自动排序的问题。

答案1

创建一个\thecaption包含累积子标题的全局宏()。

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

\newcommand{\thecaption}{}% reserve global name

\newcommand{\mysubcaption}[1]{% #1 = text
  \caption{}%
  \ifnum\value{subfigure}=1 
    \xdef\thecaption{(\thesubfigure)~#1}%
  \else
    \xdef\thecaption{\thecaption, (\thesubfigure)~#1}%
  \fi}

\begin{document}
\begin{figure}[ht]% friends don't let friends use H
\begin{minipage}{0.45\linewidth}
\begin{subfigure}{\textwidth}
\centering
        \includegraphics[width=.7\linewidth]{example-image}
        \mysubcaption{A caption}
    \end{subfigure}
    \vskip\floatsep
    \begin{subfigure}{\textwidth}
    \centering
        \includegraphics[width=.7\linewidth]{example-image}
        \mysubcaption{Another caption}
    \end{subfigure}
\end{minipage}%
\begin{minipage}{0.55\linewidth}
    \begin{subfigure}[b]{0.5\textwidth}
    \centering
        \includegraphics[width=\linewidth]{example-image}
        \mysubcaption{Yet another caption}
    \end{subfigure}%
    \begin{subfigure}[b]{0.5\textwidth}
    \centering
        \includegraphics[width=\linewidth]{example-image}
        \mysubcaption{So many captions}
    \end{subfigure}
    \vskip\floatsep
    \begin{subfigure}[b]{0.5\textwidth}
    \centering
        \includegraphics[width=\linewidth]{example-image}
        \mysubcaption{Really}
    \end{subfigure}%
    \begin{subfigure}[b]{0.5\textwidth}
    \centering
        \includegraphics[width=\linewidth]{example-image}
        \mysubcaption{I'm done with captions}
    \end{subfigure}
\end{minipage}
\caption{\thecaption.}% Note the period.
\end{figure}
\end{document}

答案2

您可以使用 来完成expl3

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

\ExplSyntaxOn

\AddToHook{env/figure/begin}
  {
    \seq_gclear:N \g_samwolfe_ac_captions_seq
  }

\NewDocumentCommand{\delayedsubcaption}{m}
  {
    \int_gincr:N \g_samwolfe_ac_label_int
    \caption{ \label{ac@\int_to_arabic:n { \g_samwolfe_ac_label_int}} }
    \seq_gput_right:Nx \g_samwolfe_ac_captions_seq
      {
        \exp_not:N \protect
        (\exp_not:N \subref {ac@\int_to_arabic:n { \g_samwolfe_ac_label_int}})
        \exp_not:n { \nobreakspace #1 }
      }
  }

\NewExpandableDocumentCommand{\printsubcaptions}{}
  {
    \seq_use:Nn \g_samwolfe_ac_captions_seq { .~ }.
  }

\int_new:N \g_samwolfe_ac_label_int
\seq_new:N \g_samwolfe_ac_captions_seq

\ExplSyntaxOff

\begin{document}

\listoffigures

\section{Main}

\begin{figure}[htp]

\begin{minipage}{0.45\linewidth}
\begin{subfigure}[b]{\textwidth}
\centering
        \includegraphics[width=.7\linewidth]{example-image}
        \delayedsubcaption{A caption}
        \label{fig1a}
    \end{subfigure}

    \begin{subfigure}[b]{\textwidth}
    \centering
        \includegraphics[width=.7\linewidth]{example-image}
        \delayedsubcaption{Another caption}
        \label{fig1b}
    \end{subfigure}
\end{minipage}\hfill
\begin{minipage}{0.55\linewidth}
    \begin{subfigure}[b]{0.5\textwidth}
    \centering
        \includegraphics[width=\linewidth]{example-image}
        \delayedsubcaption{Yet another caption}
        \label{fig1c}
    \end{subfigure}%
    \begin{subfigure}[b]{0.5\textwidth}
    \centering
        \includegraphics[width=\linewidth]{example-image}
        \delayedsubcaption{So many captions}
        \label{fig1d}
    \end{subfigure}

    \begin{subfigure}[b]{0.5\textwidth}
    \centering
        \includegraphics[width=\linewidth]{example-image}
        \delayedsubcaption{Really}
        \label{fig1e}
    \end{subfigure}%
    \begin{subfigure}[b]{0.5\textwidth}
    \centering
        \includegraphics[width=\linewidth]{example-image}
        \delayedsubcaption{I'm done with captions}
        \label{fig1f}
    \end{subfigure}
\end{minipage}
\caption{\printsubcaptions}
\label{fig1}

\end{figure}

\end{document}

您可以在主标题中添加任何内容。标签是一次性创建的,但您可以添加自己的标签以供参考。

在此处输入图片描述

我把你的改成\quad了空白行,这是“正确的做法”。

相关内容