更改回忆录中子浮点数的参考格式

更改回忆录中子浮点数的参考格式

我正在使用它memoir以及sup-float它提供的支持。这是一个 MWE(最初由 Werner 在不同的环境中制作,谢谢):

\documentclass{memoir}
\usepackage{graphicx}
\newsubfloat{figure}% Allow subfloats in figure environment
\begin{document}

\begin{figure}
  \centering
  \subbottom[Increase]{%
    \includegraphics[width=0.3\linewidth]{example-image-a}\label{fig1}}
  \subbottom[Increase]{%
    \includegraphics[width=0.3\linewidth]{example-image-b}\label{fig2}}
  \subbottom[Increase]{%
    \includegraphics[width=0.3\linewidth]{example-image-c}\label{fig3}}
  \caption{Round}
\end{figure}

Figures \ref{fig1}-\ref{fig3} and \ref{fig2}-\ref{fig3}
\end{document}

在此示例中,图形被引用为Figures 0.1(a)-0.1(c) and 0.1(b)-0.1(c),但我希望它们被引用为Figures 0.1(a-c) and 0.1(b-c)

有没有办法通过回忆录来实现这一点?

答案1

这是一个相当基本的实现,它尝试从中提取子标题“数字” \subcaptionref,假设使用默认的括号枚举。

在此处输入图片描述

\documentclass{memoir}

\usepackage{graphicx}
\newsubfloat{figure}% Allow subfloats in figure environment

\let\oldsubcaptionref\subcaptionref
\makeatletter
\@ifpackageloaded{hyperref}
  {\gdef\@firstof@{\@firstoffive}}
  {\gdef\@firstof@{\@firstoftwo}}

\renewcommand{\subcaptionref}{\@ifstar\subcaptionref@\subcaptionref@@}
\newcommand{\subcaptionref@}[1]{%
  \ifcsname r@sub@#1\endcsname
    \begingroup
    \edef\x{\csname r@sub@#1\endcsname}% Retrieve entire reference
    \edef\x{\expandafter\@firstof@\x}% Retrieve subfig reference
    \expandafter\strip@paren\x% Strip surrounding parenthesis (#1)
    \endgroup
  \else
    \textbf{??}%
  \fi
}
\newcommand{\subcaptionref@@}[1]{\oldsubcaptionref{#1}}
\def\strip@paren(#1){#1}% (#1) > #1
\makeatother

\begin{document}

\begin{figure}
  \centering
  \subbottom[Increase]{%
    \includegraphics[width=0.3\linewidth]{example-image-a}\label{fig1}}
  \subbottom[Increase]{%
    \includegraphics[width=0.3\linewidth]{example-image-b}\label{fig2}}
  \subbottom[Increase]{%
    \includegraphics[width=0.3\linewidth]{example-image-c}\label{fig3}}
  \caption{Round}\label{fig}
\end{figure}

Figures \ref{fig1}-\ref{fig3} and \ref{fig2}-\ref{fig3}.

Figures \ref{fig}(\subcaptionref*{fig1}-\subcaptionref*{fig3}) and \ref{fig}(\subcaptionref*{fig2}-\subcaptionref*{fig3}).

\end{document}

请注意如何单独引用每个组件以及如何使用新定义的带星号的版本\subcaptionref来提取子标题编号。

相关内容