使用逗号和连字符引用范围内的子图

使用逗号和连字符引用范围内的子图

我有一个 6subfloat位数的图形。

\begin{figure}
    \centering
    \subfloat[]{\includegraphics{fig1}\label{fig1}} \hfill
    \subfloat[]{\includegraphics{fig2}\label{fig2}} \hfill
    \subfloat[]{\includegraphics{fig3}\label{fig3}} \hfill
    \subfloat[]{\includegraphics{fig4}\label{fig4}} \hfill
    \subfloat[]{\includegraphics{fig5}\label{fig5}} \hfill
    \subfloat[]{\includegraphics{fig6}\label{fig6}} \hfill
    \caption{Analysis of color variation}
    \label{fig_main}
\end{figure}

我正在尝试引用子图图片标题以及文本。目前,我正在使用\ref引用图表。我需要两种引用样式,一种用连字符分隔,一种用逗号分隔。

我需要如下图的标题:Analysis of color variation. (a-c) represent color. (d-f) represent contrast, and (a-c) represent gamma.

在文中,我需要引用...as shown in Fig. 12(a, d), (b, e) and (c, f) respectively... Fig. 13(a) shows...

知道如何实现吗?如能提供任何帮助,我们将不胜感激。

答案1

这可以通过 来实现cleveref

\documentclass{article}
\usepackage{xparse}
\usepackage{subfig}
\usepackage{cleveref}

\crefformat{subfigure}{#2\onlyletter{#1}#3}
\crefrangeformat{subfigure}{(#3\onlyletter{#1}#4--#5\onlyletter{#2}#6)}
\crefmultiformat{subfigure}
  {(#2\onlyletter{#1}#3}
  {,~#2\onlyletter{#1}#3)}
  {,~#2\onlyletter{#1}#3)}
  {,~#2\onlyletter{#1}#3)}


\ExplSyntaxOn
\NewDocumentCommand{\onlyletter}{m}
 {
  \tl_set:Nx \l_tmpa_tl { #1 }
  \tl_item:Nn \l_tmpa_tl { -1 }
 }
\ExplSyntaxOff

\newcommand{\includegraphics}[1]{{\Huge #1}} % just for the example

\begin{document}

As shown in \cref{fig_main} \cref{fig1,fig4}, \cref{fig2,fig5}, and
\cref{fig3,fig6} respectively.

\begin{figure}
\centering

\subfloat[]{\includegraphics{fig1}\label{fig1}}\hfill
\subfloat[]{\includegraphics{fig2}\label{fig2}}\hfill
\subfloat[]{\includegraphics{fig3}\label{fig3}}\hfill
\subfloat[]{\includegraphics{fig4}\label{fig4}}\hfill
\subfloat[]{\includegraphics{fig5}\label{fig5}}\hfill
\subfloat[]{\includegraphics{fig6}\label{fig6}}
\caption[Analysis of color variation]{%
  Analysis of color variation;
  \cref{fig1,fig2,fig3} represent color,
  \cref{fig4,fig5,fig6} represent contrast,
  and \cref{fig1,fig2,fig3} represent gamma.%
}
\label{fig_main}

\end{figure}

\end{document}

该命令\includegraphics已被赋予适当的定义来模拟打印我没有的图形;graphicx当然,您将删除这个定义并使用。

主要问题是获取仅用字母引用的子图,这需要\onlyletter技巧。其余的是标准的cleveref

在此处输入图片描述

相关内容