考虑以下代码:
\documentclass[a4paper,12pt,openany]{book}
\usepackage[most]{tcolorbox}
\usepackage{cleveref}
\makeatletter
\makeatother
\newtcbtheorem[auto counter, number within = section]{defn}{Définition}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,}
{defn}
\newtcbtheorem[auto counter, number within = section]{theo}{Théorème}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
}{theo}
\newtcbtheorem[auto counter, number within = section]{prop}{Proposition}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
}{prop}
\newtcbtheorem[auto counter, number within = section]{lem}{Lemme}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
}{lem}
\newtcbtheorem[auto counter, number within = section]{coro}{Corollaire}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
}{coro}
\begin{document}
\chapter{CH 1}
\begin{theo}{}{}\label{A}
A
\end{theo}
\section{sec 1}
\begin{prop}{}{}\label{B}
B
\end{prop}
\section{sec 2}
\begin{lem}{}{}\label{C}
C
\end{lem}
\section{sec 3}
\begin{coro}{}{}\label{D}
D
\end{coro}
Théorème ({\color{blue}\ref{A}}), proposition ({\color{blue}\ref{B}}), lemme ({\color{blue}\ref{C}}), corollaire ({\color{blue}\ref{D}}).
\end{document}
得到的结果是:
我的问题是,我希望最后一句话是:
“ 定理(1.0.1),命题(1.1.1),引理(1.2.1),推论(1.3.1)。”
请给个想法。
答案1
与此类定理环境的交叉引用的工作方式不同。标签必须位于后面的第三个参数中\begin
,引用必须以定义中的最后一项为前缀。
由于您theo
使用最后一项定义theo
,因此引用应该是这样的\ref{theo:A}
。
我认为,除了在这里对所有内容使用更简单的前缀之外,没有什么可以做的t
。
\documentclass[a4paper,12pt,openany]{book}
\usepackage[most]{tcolorbox}
\usepackage{cleveref}
\newtcbtheorem[auto counter, number within = section]{defn}{Définition}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
}{t}
\newtcbtheorem[auto counter, number within = section]{theo}{Théorème}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
}{t}
\newtcbtheorem[auto counter, number within = section]{prop}{Proposition}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
}{t}
\newtcbtheorem[auto counter, number within = section]{lem}{Lemme}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
}{t}
\newtcbtheorem[auto counter, number within = section]{coro}{Corollaire}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
}{t}
\begin{document}
\chapter{CH 1}
\begin{theo}{}{A}
text A
\end{theo}
\section{sec 1}
\begin{prop}{}{B}
text B
\end{prop}
\section{sec 2}
\begin{lem}{}{C}
text C
\end{lem}
\section{sec 3}
\begin{coro}{}{D}
text D
\end{coro}
Théorème (\textcolor{blue}{\ref{t:A}}),
proposition (\textcolor{blue}{\ref{t:B}}),
lemme (\textcolor{blue}{\ref{t:C}}),
corollaire (\textcolor{blue}{\ref{t:D}}).
\end{document}
您可以添加对的支持cleveref
;进行调整以适应包的功能。
\documentclass[a4paper,12pt,openany]{book}
\usepackage[most]{tcolorbox}
\usepackage{cleveref}
\newtcbtheorem[auto counter, number within = section]{defn}{Définition}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
label type=defn,
}{t}
\newtcbtheorem[auto counter, number within = section]{theo}{Théorème}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
label type=theo,
}{t}
\newtcbtheorem[auto counter, number within = section]{prop}{Proposition}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
label type=prop,
}{t}
\newtcbtheorem[auto counter, number within = section]{lem}{Lemme}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
label type=lem,
}{t}
\newtcbtheorem[auto counter, number within = section]{coro}{Corollaire}{
colback=green!5,
colframe=green!35!black,
fonttitle=\bfseries,
label type=coro,
}{t}
\crefname{defn}{définition}{définitions}
\crefname{theo}{théorème}{théorèmes}
\crefname{prop}{proposition}{propositions}
\crefname{coro}{corollaire}{corollaires}
\crefname{lem}{lemme}{lemmes}
\begin{document}
\chapter{CH 1}
\begin{theo}{}{A}
text A
\end{theo}
\section{sec 1}
\begin{prop}{}{B}
text B
\end{prop}
\section{sec 2}
\begin{lem}{}{C}
text C
\end{lem}
\section{sec 3}
\begin{coro}{}{D}
text D
\end{coro}
\Cref{t:A}, \cref{t:B}, \cref{t:C}, \cref{t:D}.
Théorème (\textcolor{blue}{\ref{t:A}}),
proposition (\textcolor{blue}{\ref{t:B}}),
lemme (\textcolor{blue}{\ref{t:C}}),
corollaire (\textcolor{blue}{\ref{t:D}}).
\end{document}