有没有办法引用彩色盒子创建定理(使用 创建\newtcbtheorem
)使用超链接的\autoref
?
我试图设置\<name>autorefname
,就像我对用 创建的定理所做的那样\newtheorem
,但它似乎不适用于\newtcbtheorem
:
\documentclass{article}
\usepackage{hyperref}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
% tcolorbox theorem
\newtcbtheorem{evidence}{Evidence}{}{ev}
\newcommand{\evidenceautorefname}{Evidence}
% classic theorem
\newtheorem{classicevidence}{Evidence}
\newcommand{\classicevidenceautorefname}{Evidence}
\begin{document}
Find the most important text
in~\autoref{ev:one} % Does not work correctly
and in~\autoref{ev:two}. % Works as expected
\begin{evidence}{This is the evidence}{one}
Nothing really important to show here.
\end{evidence}
\begin{classicevidence}
\label{ev:two}
This is the classic evidence.
\end{classicevidence}
\end{document}
答案1
处理示例文档时,您会收到警告
Package hyperref Warning: No autoref name for
`tcb@cnt@evidence' on input line 18.
这表明autoref
无法识别新环境,并且还向您显示与其关联的内部名称:tcb@cnt@evidence
因此,在内部,您的环境名称不是evidence
但tcb@cnt@evidence
,这解释了您的尝试失败的原因。您需要让autoref
知道tcb@cnt@evidence
:
\newcommand\tcb@cnt@evidenceautorefname{Evidence}
代码:
\documentclass{article}
\usepackage{hyperref}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
% tcolorbox theorem
\newtcbtheorem{evidence}{Evidence}{}{ev}
\makeatletter
\newcommand\tcb@cnt@evidenceautorefname{Evidence}
\makeatother
% classic theorem
\newtheorem{classicevidence}{Evidence}
\newcommand{\classicevidenceautorefname}{Evidence}
\begin{document}
Find the most important text
in~\autoref{ev:one} % Does not work correctly
and in~\autoref{ev:two}. % Works as expected
\begin{evidence}{This is the evidence}{one}
Nothing really important to show here.
\end{evidence}
\begin{classicevidence}
\label{ev:two}
This is the classic evidence.
\end{classicevidence}
\end{document}
答案2
该tcolorbox
包提供了一些很好的钩子,使其与cleveref
包协作。解决方案包括 (a) 在设置定理时提供“标签类型”,然后使用指令告诉 cleveref 如何排版该标签类型的交叉引用。最后,可以使包的\crefname
命令生成与使用该选项加载包生成的交叉引用相同的交叉引用。\cref
cleveref
\autoref
cleveref
nameinlink
有关各种 LaTeX 交叉引用包和宏(包括\autoref
和)的详细讨论\cref
,请参阅帖子交叉引用包:使用哪个,哪些有冲突以及相关答案。
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
% tcolorbox theorem
\newtcbtheorem{evidence}{Evidence}{label type=evidence}{ev}
\usepackage[colorlinks=true]{hyperref}
\usepackage[nameinlink]{cleveref} % make \cref emulate look of \autoref
\crefname{evidence}{Evidence}{Evidence}
\begin{document}
\noindent
Find the most important text in~\cref{ev:one}. % Now works as expected
\begin{evidence}{This is the evidence}{one}
Nothing really important to show here.
\end{evidence}
\end{document}
答案3
您还可以使用您喜欢的计数器\newtcbtheorem
。在下面的代码中,classicevidence
采用了允许两种环境混合运行的计数器。
或者,使用\newcounter{mynicecounter}
并将此计数器\newtcbtheorem
赋予use counter=mynicecounter
。
\documentclass{article}
\usepackage{hyperref}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
% classic theorem
\newtheorem{classicevidence}{Evidence}
\newcommand{\classicevidenceautorefname}{Evidence}
% tcolorbox theorem
\newtcbtheorem[use counter=classicevidence]{evidence}{Evidence}{}{ev}
\begin{document}
Find the most important text
in~\autoref{ev:one} % Works as expected
and in~\autoref{ev:two}. % Works as expected
\begin{evidence}{This is the evidence}{one}
Nothing really important to show here.
\end{evidence}
\begin{classicevidence}
\label{ev:two}
This is the classic evidence.
\end{classicevidence}
\end{document}