有没有办法修复 cleveref 包关于子浮点数引用的限制?

有没有办法修复 cleveref 包关于子浮点数引用的限制?

使用命令引用浮点数时\cref,有时可能会产生错误的排版。当包含子浮点数时尤其如此。

例如,当我们有浮点数 1 和两个子浮点数时,范围1a and 2 to 5将被误认为来自1a to 5。此外,如果源代码引用中同时包含1a1b,则应该提及源代码中包含的所有子浮点数,而不仅仅是其中一个(参见第 2 点)。排版输出如下所示:

在此处输入图片描述

此输出是使用以下源代码生成的:

\documentclass[twocolumn]{report}

\usepackage{float}
\usepackage{subfloat}
\usepackage{caption}
\usepackage{cleveref}
\usepackage{paralist}



\begin{document}


    \begin{subfigures}

        % Subfigure 1
        \begin{figure}[H]

            \centering
            \fbox{\Huge Figure 1a}


            \caption{Caption 1}
            \label{fig1a}

        \end{figure}


        % Subfigure 2
        \begin{figure}[H]

            \centering
            \fbox{\Huge Figure 1b}


            \caption{Caption 1b}
            \label{fig1b}

        \end{figure}


    \end{subfigures}


    % Figure 2
    \begin{figure}[H]

        \centering
        \fbox{\Huge Figure 2}


        \caption{Caption 2}
        \label{fig2}

    \end{figure}


    % Figure 3
    \begin{figure}[H]

        \centering
        \fbox{\Huge Figure 3}


        \caption{Caption 3}
        \label{fig3}

    \end{figure}


    % Figure 4
    \begin{figure}[H]

        \centering
        \fbox{\Huge Figure 4}


        \caption{Caption 4}
        \label{fig4}

    \end{figure}


    % Figure 5
    \begin{figure}[H]

        \centering
        \fbox{\Huge Figure 5}


        \caption{Caption 5}
        \label{fig5}

    \end{figure}


    % Figure 6
    \begin{figure}[H]

        \centering
        \fbox{\Huge Figure 6}


        \caption{Caption 6}
        \label{fig6}

    \end{figure}



    \newpage
    Figures are correctly cited for different citation formats such as:

    \begin{enumerate}

        \item Multiple: \textbf{\cref{fig5,,fig3,,fig4,,fig2}}
        \item Range: \textbf{\cref{fig5,fig3,fig4}}
        \item Multiple and range: \textbf{\cref{fig2,fig4,fig3,fig6}}

    \end{enumerate}


    \vspace{5mm}
    But once subfigures are included, some citations formats do not work:

    \begin{enumerate}

    \item Multiple (works): \textbf{\cref{fig3,,fig4,,fig2,,fig1a}}
    \item Range: \textbf{\cref{fig1a,fig1b,fig5,fig3,fig4}} (the output should be \textbf{figs. 1a to 1b and 3 to 5})
    \item Multiple and range: \textbf{\cref{fig1a,fig2,fig4,fig3,fig6}} (the output should be \textbf{figs. 1a, 2 to 4 and 6})

    \end{enumerate}


\end{document}

我已经有了一个可以缓解该问题的解决方案,但是与上述预期的输出并不相同。

答案1

在此处输入图片描述 我们可以定义新的浮点类型(subfigcleveref

\crefformat{subfig}{fig. #1}
\crefrangeformat{subfig}{figs. #1 to #2}
\crefmultiformat{subfig}{figs. #1}{ and #1}{, #1}{ and #1}
\crefrangemultiformat{subfig}{figs. #1 to #2}{}{}{}

然后在序言中我们定义一个新命令:

\newcommand{\labelsf}[1]{ \label[subfig]{#1} } % a new command for labeling subfigures

labelsf现在可以用来标记子图。

完整源代码如下所示:

\documentclass[twocolumn]{report}

\usepackage{float}
\usepackage{subfloat}
\usepackage{caption}
\usepackage{paralist}

\usepackage{cleveref}
\crefformat{subfig}{fig. #1}
\crefrangeformat{subfig}{figs. #1 to #2}
\crefmultiformat{subfig}{figs. #1}{ and #1}{, #1}{ and #1}
\crefrangemultiformat{subfig}{figs. #1 to #2}{}{}{}
\newcommand{\labelsf}[1]{ \label[subfig]{#1} } % a new command for labeling subfigures

\begin{document}


    \begin{subfigures}

        % Subfigure 1
        \begin{figure}[H]

            \centering
            \fbox{\Huge Figure 1a}


            \caption{Caption 1}
            \labelsf{fig1a}

        \end{figure}


        % Subfigure 2
        \begin{figure}[H]

            \centering
            \fbox{\Huge Figure 1b}


            \caption{Caption 1b}
            \labelsf{fig1b}

        \end{figure}


    \end{subfigures}


    % Figure 2
    \begin{figure}[H]

        \centering
        \fbox{\Huge Figure 2}


        \caption{Caption 2}
        \label{fig2}

    \end{figure}


    % Figure 3
    \begin{figure}[H]

        \centering
        \fbox{\Huge Figure 3}


        \caption{Caption 3}
        \label{fig3}

    \end{figure}


    % Figure 4
    \begin{figure}[H]

        \centering
        \fbox{\Huge Figure 4}


        \caption{Caption 4}
        \label{fig4}

    \end{figure}


    % Figure 5
    \begin{figure}[H]

        \centering
        \fbox{\Huge Figure 5}


        \caption{Caption 5}
        \label{fig5}

    \end{figure}


    % Figure 6
    \begin{figure}[H]

        \centering
        \fbox{\Huge Figure 6}


        \caption{Caption 6}
        \label{fig6}

    \end{figure}



    \newpage
    Figures are correctly cited for different citation formats such as:

    \begin{enumerate}

        \item Multiple: \textbf{\cref{fig5,,fig3,,fig4,,fig2}}
        \item Range: \textbf{\cref{fig5,fig3,fig4}}
        \item Multiple and range: \textbf{\cref{fig2,fig4,fig3,fig6}}

    \end{enumerate}


    \vspace{5mm}
    But once subfigures are included, some citations formats do not work:

    \begin{enumerate}

    \item Multiple (works): \textbf{\cref{fig3,,fig4,,fig2,,fig1a}}
    \item Range: \textbf{\cref{fig1a,fig1b,fig5,fig3,fig4}} (the output should be \textbf{figs. 1a to 1b and 3 to 5})
    \item Multiple and range: \textbf{\cref{fig1a,fig2,fig4,fig3,fig6}} (the output should be \textbf{figs. 1a, 2 to 4 and 6})

    \end{enumerate}


\end{document}

cref现在可以正确引用子图,但是该解决方案的缺点是:

  • 我们无法通过双击浮点数的标签来找到它的用法,也无法通过单击浮点数的标签来找到浮点数的源代码
  • 浮标的名称有时会重复两次,这是多余的

相关内容