如何交叉引用子图的名称

如何交叉引用子图的名称

我有一个文档,其中使用了图形和子图(由包提供subcaption)。当我使用交叉引用子图时,我得到了正确的交叉引用,例如“图 1a”,但当我尝试通过或\Cref{subfigure-label}仅获取其名称(即“图形”)时,我只得到问号。\nameCref{subfigure-label}\lcnamecref{subfigure-label}

我怎样才能获得交叉引用的子图的名称,即“图”或(如果可能的话)“子图”而不是问号?

在此处输入图片描述

这里是 MWE

\documentclass[10pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{cleveref}
\usepackage{subcaption}
\begin{document}

    \begin{figure}
        %First landscape as subfigure
        \begin{subfigure}[t]{0.4\textwidth}
            \includegraphics[width=\textwidth]{landscape.jpeg}
            \caption{first landscape}\label{fig:landscape-1}
        \end{subfigure}\hspace{0.2\textwidth}
        %Second landscape as subfigure
        \begin{subfigure}[t]{0.4\textwidth}
            \includegraphics[width=\textwidth]{landscape.jpeg}
            \caption{second landscape}\label{fig:landscape-2}
        \end{subfigure}
    \caption{Two landscapes}\label{fig:landscapes}
    \end{figure}

    %Text cross-referencing the figures and subfigures
    Above there is a \lcnamecref{fig:landscapes}, its name is \Cref{fig:landscapes}.\\
    \Cref{fig:landscape-1} is a beautiful landscape, and so in \Cref{fig:landscape-2}.
    The first landscape is a \lcnamecref{fig:landscape-1} 
    and the second is a \nameCref{fig:landscape-2} too. 

\end{document}

谢谢!

答案1

您必须告知计数器引用信息cleveref的含义subfigure。这在 中尚未完成cleveref,因此需要\crefname{subfigure}{figure}{figures}和,否则会显示 。\Crefname{subfigure}{Figure}{Figures}??

如果需要/期望,则更改为figuresubfigure

cleveref即使在之后,也应该在最后一个包中加载hyperref

\documentclass[10pt,a4paper]{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\usepackage{cleveref}

\crefname{subfigure}{figure}{figures}
\Crefname{subfigure}{Figure}{Figures}
\begin{document}

    \begin{figure}
        %First landscape as subfigure
        \begin{subfigure}[t]{0.4\textwidth}
            \includegraphics[width=\textwidth]{landscape.jpeg}
            \caption{first landscape}\label{fig:landscape-1}
        \end{subfigure}\hspace{0.2\textwidth}
        %Second landscape as subfigure
        \begin{subfigure}[t]{0.4\textwidth}
            \includegraphics[width=\textwidth]{landscape.jpeg}
            \caption{second landscape}\label{fig:landscape-2}
        \end{subfigure}
    \caption{Two landscapes}\label{fig:landscapes}
    \end{figure}

    %Text cross-referencing the figures and subfigures
    Above there is a \lcnamecref{fig:landscapes}, its name is \Cref{fig:landscapes}.\\
    \Cref{fig:landscape-1} is a beautiful landscape, and so in \Cref{fig:landscape-2}.
    The first landscape is a \lcnamecref{fig:landscape-1} 
    and the second is a \nameCref{fig:landscape-2} too. 

\end{document}

相关内容