一直\autoref
写的是“sezione”(部分)而不是“Teorema”(定理),我尝试了不同的解决方案(甚至是“ %
”解决方案),但它们对我来说根本不起作用... 这是我的代码的一段简短摘录。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{todonotes}
\usepackage{amsthm}
\usepackage{hyperref}
\theoremstyle{definition}\newtheorem{definition}{\todo[inline, inlinewidth=2.3cm, noinlinepar, color=green!40]{Definizione}}[section]
\newtheorem{theorem}[definition]{\todo[inline, inlinewidth=1.9cm, noinlinepar, color=red!40]{Teorema}}
%\providecommand*{\theoremautorefname}{Teorema}
%\addto\extrasitalian{\renewcommand{\theoremautorefname}{Teorema}}
\begin{document}
\begin{theorem}\label{bla}
Bla bla bla
\end{theorem}
%\begin{proposition}
Blu blu blu $\implies$ \autoref{bla}.
%\end{proposition}
\end{document}
答案1
我建议您按此顺序加载amsthm
、hyperref
和(新)cleveref
包,然后才执行\theoremstyle
和\newtheorem
指令。接下来,在文档正文中,我建议您使用\cref
而不是\autoref
来生成交叉引用,而不必担心todo
和hyperref
包之间的(明显)交互。
如果您cleveref
使用选项加载包italian
,则会自动获得标签“定理”和“定义”的意大利语对应词(“teorema”和“definizione”)以及意大利语版本的语言连词(例如,“e”而不是“and”等)。[附言:我发现意大利语设置命令中有一个错误,它与环境中使用的标签有关definition
。在下面的代码中,我建议插入指令\crefname{definition}{definizione}{definizioni}
作为先发制人的错误修复。]
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{amssymb,amsmath,todonotes}
\usepackage{amsthm}
\usepackage[colorlinks,allcolors=blue]{hyperref}
\usepackage[nameinlink,italian]{cleveref} % <-- option 'italian'
\crefname{definition}{definizione}{definizioni} % preemptive bug fix
\theoremstyle{definition}
\newtheorem{definition}{\todo[inline, inlinewidth=2.3cm,
noinlinepar, color=green!40]{Definizione}}[section]
\newtheorem{theorem}[definition]{\todo[inline, inlinewidth=1.9cm,
noinlinepar, color=red!40]{Teorema}}
\begin{document}
\setcounter{section}{3}
\begin{theorem}\label{bla} Bla bla bla \end{theorem}
\begin{definition}\label{ble} Ble ble ble \end{definition}
\autoref{bla} % <-- still incorrect
\cref{bla,ble} % <-- but \cref is correct
\end{document}
答案2
有两个问题。一个是它\todo
在某种程度上与\autoref
机制冲突;另一个是你需要使用aliascnt
。
我\todo
用tcolorbox
功能替换了:这是一个专门的包,而不是类似的黑客包\todo
。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{tcolorbox}
\usepackage{aliascnt}
\usepackage{hyperref}
\newtcbox{\thmtcbox}[1]{
colback=#1,
tcbox raise base,
left=0.4pt,
top=0.4pt,
right=0.4pt,
bottom=0.4pt,
boxrule=0.4pt,
}
\theoremstyle{definition}
\newtheorem{definition}{\thmtcbox{green!40}{Definizione}}[section]
\newaliascnt{theorem}{definition}
\newtheorem{theorem}[theorem]{\thmtcbox{red!40}{Teorema}}
\aliascntresetthe{theorem}
\providecommand*{\definitionautorefname}{Definizione}
\begin{document}
\begin{theorem}\label{bla}
Bla bla bla
\end{theorem}
\begin{definition}\label{blu}
Blu blu blu $\implies$ \autoref{bla}.
\end{definition}
\autoref{blu}
\end{document}
不过,cleveref
更好。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{tcolorbox}
\usepackage{hyperref}
\usepackage{cleveref}
\newtcbox{\thmtcbox}[1]{
colback=#1,
tcbox raise base,
left=0.4pt,
top=0.4pt,
right=0.4pt,
bottom=0.4pt,
boxrule=0.4pt,
}
\theoremstyle{definition}
\newtheorem{definition}{\thmtcbox{green!40}{Definizione}}[section]
\newtheorem{theorem}[definition]{\thmtcbox{red!40}{Teorema}}
\crefname{definition}{definizione}{definizioni}
\Crefname{definition}{Definizione}{Definizioni}
\crefname{theorem}{teorema}{teoremi}
\Crefname{theorem}{Teorema}{Teoremi}
\begin{document}
\begin{theorem}\label{bla}
Bla bla bla
\end{theorem}
\begin{definition}\label{blu}
Blu blu blu $\implies$ \cref{bla}.
\end{definition}
\Cref{blu}
\end{document}
如果你打电话
\usepackage[nameinlink]{cleveref}
链接将包含名称。