我面临的问题是,在 tcbtheorem 环境本身中,定义的 tcbtheorem 的编号是正确编号的,但 autoref 通常显示不同的数字,或卡在编号中。
一个小例子如下:
\documentclass{book}
% General document formatting
\usepackage[margin=0.7in]{geometry}
\usepackage[parfill]{parskip}
\usepackage[utf8]{inputenc}
% hyperref & url package
\usepackage[
hidelinks
]{hyperref}
\usepackage{bookmark}
\usepackage{url}
\usepackage[most]{tcolorbox}
\newtcbtheorem[auto counter, number within=chapter, number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}}]{definition}{Definition}{}{def}
\makeatletter
\newcommand\definitionautorefname{Definition}
\makeatother
\begin{document}
\chapter{First Chapter}
%
\section{First Section}
%
We state in \autoref{def:life} an attitude.
%
\begin{definition}{Life\label{def:life}}
_Life is fun.
\end{definition}
%
We state in \autoref{def:work} a fact.
%
\begin{definition}{Work\label{def:work}}
_Work is a necessity.
\end{definition}
\section{Second Section}
%
%
We state in \autoref{def:latex} a truth.
%
\begin{definition}{Latex\label{def:latex}}
_Latex is not so much fun.
\end{definition}
%
\end{document}
编译后,示例显示 autoref 中的编号已关闭,并且似乎已粘在节上。定义环境中的编号是正确的(参见下图)
我该怎么做才能让 autoref 使用相应环境中所述的数字来引用定义?
谨致问候,亚历克斯
答案1
您使用了错误的输入语法(您应该在日志中收到有关def_
您正在生成的标签的警告)。新环境有二强制参数,其中第二个将构建标签:
\documentclass{book}
% General document formatting
\usepackage[margin=0.7in]{geometry}
\usepackage[parfill]{parskip}
\usepackage[utf8]{inputenc}
% hyperref & url package
\usepackage[
hidelinks
]{hyperref}
\usepackage{bookmark}
\usepackage{url}
\usepackage[most]{tcolorbox}
\newtcbtheorem[auto counter, number within=chapter, number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}}]{definition}{Definition}{}{def}
\makeatletter
\newcommand\definitionautorefname{Definition}
\makeatother
\begin{document}
\chapter{First Chapter}
%
\section{First Section}
%
We state in \autoref{def:life} an attitude.
%
\begin{definition}{Life}{life}
Life is fun.
\end{definition}
%
We state in \autoref{def:work} a fact.
%
\begin{definition}{Work}{work}
Work is a necessity.
\end{definition}
\section{Second Section}
%
%
We state in \autoref{def:latex} a truth.
%
\begin{definition}{Latex}{latex}
Latex is not so much fun.
\end{definition}
%
\end{document}