Cleveref 和方程式标签包冲突

Cleveref 和方程式标签包冲突

我正在使用这个模板 http://www.latextemplates.com/template/masters-doctoral-thesis

\documentclass[
11pt, % The default document font size, options: 10pt, 11pt, 12pt
english, % ngerman for German
singlespacing, % Single line spacing, alternatives: onehalfspacing or doublespacing
]{MastersDoctoralThesis} % The class file specifying the document structure

\usepackage{amsmath,tensor} % matrix, vector
\usepackage{cleveref} 

\begin{document}

\begin{equation}\label{eq:a}
{{\rm{a}}_{r,c,l}} \in \{ 0,1, \ldots ,n\}
\end{equation}

Just ref \ref{eq:a}

Clever \Cref{eq:a} 

\end{document}

出现错误

参考第 1 页上的“eq:a”在输入行 62 上未定义。

我的最小例子: https://www.overleaf.com/read/ktmqbhnvsdww


添加内容MastersDoctoralThesis.cls

\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\newcommand{\classname}{MastersDoctoralThesis}
\ProvidesClass{\classname}[2016/11/22 v1.5 LaTeXTemplates.com]
\providecommand{\baseclass}{book}
\RequirePackage{etoolbox}
\RequirePackage{xparse}
\newbool{hyperrefsupport}
\booltrue{hyperrefsupport}
\newbool{headsepline}

\DeclareOption{nohyperref}{\boolfalse{hyperrefsupport}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\baseclass}}

\ProcessOptions\relax

\LoadClass{\baseclass}

%----------------------------------------------------------------------------------------
%   REQUIRED PACKAGES
%----------------------------------------------------------------------------------------

\RequirePackage{babel} % Required for automatically changing names of document elements to languages besides english

\RequirePackage{scrbase} % Required for handling language-dependent names of sections/document elements

\RequirePackage{scrhack} % Loads fixes for various packages

\RequirePackage{setspace} % Required for changing line spacing

\RequirePackage{longtable} % Required for tables that span multiple pages (used in the symbols, abbreviations and physical constants pages)

\RequirePackage{siunitx} % Required for \SI commands

\RequirePackage{graphicx} % Required to include images
\graphicspath{{Figures/}{./}} % Specifies where to look for included images

\RequirePackage{booktabs} % Required for better table rules

\RequirePackage{caption} % Required for customising the captions
\captionsetup{justification=centerlast,font=small,labelfont=sc,margin=50pt}

%----------------------------------------------------------------------------------------
%   MARGINS
%----------------------------------------------------------------------------------------

\RequirePackage{geometry}
\geometry{
    headheight=27.2pt,
    includehead,
    includefoot
}

\raggedbottom


%----------------------------------------------------------------------------------------

\ifbool{hyperrefsupport}{% If the nohyperref class option has not been specified
\AtEndPreamble{\RequirePackage{hyperref}
\hypersetup{
pdfpagemode={UseOutlines},
bookmarksopen=true,
bookmarksopenlevel=0,
hypertexnames=false,
colorlinks=true,% Set to false to disable coloring links
citecolor=blue,% The color of citations
linkcolor=blue,% The color of references to document elements (sections, figures, etc)
urlcolor=blue,% The color of hyperlinks (URLs)
pdfstartview={FitV},
unicode,
breaklinks=true,
}

\pdfstringdefDisableCommands{% If there is an explicit linebreak in a section heading (or anything printed to the pdf-bookmarks), it is replaced by a space
    \let\\\space%
}
    }
}{%nothing
}

%----------------------------------------------------------------------------------------

\endinput
% lazyLizardTracer

答案1

您必须cleveref在之后加载hyperref- 因为您的类只hyperref在序言的末尾加载,所以您必须执行相同的技巧:

\documentclass[
11pt, % The default document font size, options: 10pt, 11pt, 12pt
english, % ngerman for German
singlespacing, % Single line spacing, alternatives: onehalfspacing or doublespacing
]{MastersDoctoralThesis} % The class file specifying the document structure

\usepackage{amsmath,tensor} % matrix, vector
\AtEndPreamble{\usepackage{cleveref}} 

\begin{document}

\begin{equation}\label{eq:a}
{{\rm{a}}_{r,c,l}} \in \{ 0,1, \ldots ,n\}
\end{equation}

Just ref \ref{eq:a}

Clever \Cref{eq:a} 

\end{document}

在此处输入图片描述

相关内容