通过编译 LaTeX 文件,我收到以下消息:
`' multiply defined
和
`@cref' multiply defined
什么原因导致此问题以及如何解决?以下是我的代码(示例):
\documentclass{report}
\usepackage{enumitem}
\usepackage[many]{tcolorbox}
\usepackage[dvips,colorlinks,bookmarks]{hyperref}
\hypersetup{linkcolor=blue,citecolor=blue,filecolor=blue,urlcolor=blue}
\usepackage[capitalize, nameinlink]{cleveref}
\usepackage{nicematrix} % I need this package
\newtcolorbox[auto counter,number within=chapter,crefname={theorem}{theorems}]{theo}[2][]{%
breakable,enhanced,colback=blue!5!white,
colframe=blue!75!black,
colbacktitle=cyan!50!green,
coltitle=blue!25!black,
fonttitle=\bfseries,
subtitle style={boxrule=0.4pt,colback=cyan!50!red!25!white},title=Theorem~\thetcbcounter~#2,label=#1}
\begin{document}
\begin{enumerate}[label=\color{blue}\bfseries\arabic*.,
ref=\color{blue}\bfseries\arabic*.]
\item\label{e1} My equation
\item\label{e2}
\end{enumerate}
\begin{theo}[]{}
\begin{enumerate}[label=\color{blue}\bfseries\alph*)]
\item My \ref{e1} and \ref{e2}
\end{enumerate}
\end{theo}
\begin{theo}[]{}
\begin{enumerate}[label=\color{blue}\bfseries\alph*)]
\item Again, my \ref{e1} and \ref{e2}
\end{enumerate}
\end{theo}
\end{document}
谢谢。
答案1
您已指定\newtcolorbox
要接收的参数label=#1
,这实际上让人怀疑这是否应该是一个可选参数,或者是否应该将其正确处理为可选参数(我将在下面采取第二种立场)。而且,最重要的是,您使用一个空的可选参数调用了您创建的 tcolorboxes,这意味着环境试图创建一个具有空值的标签,并且由于您使用cleveref
,因此还会创建一个伴随@cref
引用。由于您使用了两次环境,因此它们都被多次定义。
您最好将可选参数定义为 tcolorbox 的一组最终的任意选项,而不是将其硬编码为label=
。
\documentclass{report}
\usepackage{enumitem}
\usepackage[many]{tcolorbox}
\usepackage[colorlinks,bookmarks]{hyperref}
\hypersetup{linkcolor=blue,citecolor=blue,filecolor=blue,urlcolor=blue}
\usepackage[capitalize, nameinlink]{cleveref}
\usepackage{nicematrix} % I need this package
\newtcolorbox[
auto counter,
number within=chapter,
crefname={theorem}{theorems}
]{theo}[2][]{%
breakable,
enhanced,
colback=blue!5!white,
colframe=blue!75!black,
colbacktitle=cyan!50!green,
coltitle=blue!25!black,
fonttitle=\bfseries,
subtitle style={boxrule=0.4pt,colback=cyan!50!red!25!white},
title=Theorem~\thetcbcounter~#2,
#1 % this is the relevant change, instead of `label=#1'.
}
\begin{document}
\chapter{Chapter 1}
\begin{enumerate}[label=\color{blue}\bfseries\arabic*.,
ref=\color{blue}\bfseries\arabic*.]
\item\label{e1} My equation
\item\label{e2}
\end{enumerate}
\begin{theo}[label=theo1]{Important theorem}
\begin{enumerate}[label=\color{blue}\bfseries\alph*)]
\item My \ref{e1} and \ref{e2}
\end{enumerate}
\end{theo}
\begin{theo}[label=theo2]{Another theorem}
\begin{enumerate}[label=\color{blue}\bfseries\alph*)]
\item Again, my \ref{e1} and \ref{e2}
\end{enumerate}
\end{theo}
\cref{theo1,theo2}
% But you can also have an unlabeled one, if you need it.
\begin{theo}{Yet another theorem}
\begin{enumerate}[label=\color{blue}\bfseries\alph*)]
\item Again, my \ref{e1} and \ref{e2}
\end{enumerate}
\end{theo}
\end{document}