
考慮以下程式碼:
\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}