那些天我写了一本书,我用了框架框tcolorbox
。看一看:
\documentclass[12pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{tcolorbox,xcolor}
\theoremstyle{definition}
\makeatletter
\tcbuselibrary{theorems}
\newtcbtheorem[number within=section]{mytheo}{Theorem}%
{colback=black!5,colframe=red!35!black,fonttitle=\bfseries}{th}
\newtcbtheorem[number within=section]{myprop}{Proposition}%
{colback=black!5,colframe=red!50!black,fonttitle=\bfseries}{th}
\newtcbtheorem[number within=section]{mylem}{Lemma}%
{colback=black!5,colframe=red!50!black,fonttitle=\bfseries}{th}
\newtcbtheorem[number within=section]{mypor}{Corollary}%
{colback=black!5,colframe=red!35!black,fonttitle=\bfseries}{th}
\newtcbtheorem[number within=section]{myax}{Axiom}%
{colback=black!5,colframe=blue!35!black,fonttitle=\bfseries}{th}
\renewcommand{\rmdefault}{udidot}
\begin{document}
\newtheorem{defin}{Definition}[section]
\newtheorem{prt}{Remark}[section]
\newtheorem{prts}{Remarks}[section]
\newtheorem{exmp}{Example}[section]
\newtheorem{exmps}{Examples}[section]
\newtheorem*{note}{Note}
\chapter{Maximal and Prime Ideals}
\section{Maximal Ideals}
\begin{defin}
Let $R$ a commutative ring with $1_R$ ...
\end{defin}
\begin{myprop}{Maximal Ideals Criterion}{}
\label{Max Id Crit}
Let $R$ a commutative ring with $1_R$ ...
\end{myprop}
From the Proposition \ref{Max Id Crit}, ...
\end{document}
正如你所看到的,我只想将这些框架用于定理、命题、引理、推论和公理(以及不是定义)。我还想保留写下其中一些内容的选择(例如,定理)没有这些框架。
我的问题是:
- 我们如何才能在整个文本中进行连续编号?
- 如您所见,我们在定理等的引用中面临标签问题。我们该如何解决它?
答案1
- tcbtheorem 环境允许您使用其他 tcbtheorems 的计数器以及现有的 LaTeX 计数器。首先定义标准 LaTeX 定理(所有定理共享同一个计数器),然后再定义 tcbtheorems(使用同一个计数器),这样会更容易。
- 问题在于,需要将 tcbtheorem 环境的标签作为选项传递给该环境,才能使其正常工作。这不是标准的 LaTeX 行为(您会注意到,标记和引用您的定义环境会顺利进行)。
\documentclass[12pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{tcolorbox,xcolor}
\theoremstyle{definition}
% Define amsthm theorems first
\newtheorem{defin}{Definition}[section] % Creates a new counter, number within section
\newtheorem{prt}[defin]{Remark} % Putting [defin] in second position uses defin's counter instead of creating a new one
\newtheorem{prts}[defin]{Remarks} % Again share defin's counter
\newtheorem{exmp}[defin]{Example} % etc.
\newtheorem{exmps}[defin]{Examples}
\newtheorem*{note}{Note}
\tcbuselibrary{theorems}
% use counter*=defin to make each tcbtheorem share defin's counter
\newtcbtheorem[use counter*=defin, number within=section]{mytheo}{Theorem}%
{colback=black!5,colframe=red!35!black,fonttitle=\bfseries}{th}
\newtcbtheorem[use counter*=defin, number within=section]{myprop}{Proposition}%
{colback=black!5,colframe=red!50!black,fonttitle=\bfseries}{th}
\newtcbtheorem[use counter*=defin, number within=section]{mylem}{Lemma}%
{colback=black!5,colframe=red!50!black,fonttitle=\bfseries}{th}
\newtcbtheorem[use counter*=defin, number within=section]{mypor}{Corollary}%
{colback=black!5,colframe=red!35!black,fonttitle=\bfseries}{th}
\newtcbtheorem[use counter*=defin, number within=section]{myax}{Axiom}%
{colback=black!5,colframe=blue!35!black,fonttitle=\bfseries}{th}
\renewcommand{\rmdefault}{udidot}
\begin{document}
\chapter{Maximal and Prime Ideals}
\section{Maximal Ideals}
% Normal labelling
\begin{defin} \label{first_def}
Let $R$ a commutative ring with $1_R$ ...
\end{defin}
% tcbtheorem labelling
\begin{myprop}[label=prop:maximal]{Maximal Ideals Criterion}{}
Let $R$ a commutative ring with $1_R$ ...
\end{myprop}
From the Proposition \ref{prop:maximal} and definition \ref{first_def}\ldots
\end{document}
输出:
另外,我建议使用cleveref
可以轻松设置每个 tcbtheorem 的包,以便生成命名引用而不仅仅是数字,例如“命题 1.1.2”与“1.1.2”。这样,您就不必每次都担心自己是在引用定理、定义还是命题等。
\makeatletter
仅供参考,你的代码中有一个流氓。
答案2
关键是彩色盒子选项use counter=<another counter>
和use counter from= <counter from another tcolorbox>
更新考虑到 OP 的评论:
\documentclass[12pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{tcolorbox,xcolor}
\theoremstyle{definition}
%\makeatletter
\tcbuselibrary{theorems}
\newtcbtheorem[number within=section,use counter=defin]{mytheo}{Theorem}%
{colback=black!5,colframe=red!35!black,fonttitle=\bfseries}{th}
\newtcbtheorem[number within=section,use counter =defin]{myprop}{Proposition}%
{colback=black!5,colframe=red!50!black,fonttitle=\bfseries}{th}
\newtcbtheorem[number within=section,use counter= defin]{mylem}{Lemma}%
{colback=black!5,colframe=red!50!black,fonttitle=\bfseries}{th}
\newtcbtheorem[number within=section,use counter=defin]{mycor}{Corollary}%
{colback=black!5,colframe=red!35!black,fonttitle=\bfseries}{th}
\newtcbtheorem[number within=section,use counter=defin]{myax}{Axiom}%
{colback=black!5,colframe=blue!35!black,fonttitle=\bfseries}{th}
\renewcommand{\rmdefault}{udidot}
\begin{document}
\newtheorem{defin}{Definition}[section]
\newtheorem{prt}[defin]{Remark}
\newtheorem{prts}[defin]{Remarks}
\newtheorem{exmp}[defin]{Example}%[section]
\newtheorem{exmps}[defin]{Examples}
\newtheorem*{note}{Note}
\chapter{Maximal and Prime Ideals}
\section{Maximal Ideals}
\begin{defin}
\label{def:commutative ring}
Let $R$ a commutative ring with $1_R$ ...
\end{defin}
\begin{myprop}{Maximal Ideals Criterion}{Max Id Crit}
Let $R$ a commutative ring with $1_R$ ...
\end{myprop}
From the Proposition \ref{th:Max Id Crit},
See definition \ref{def:commutative ring}
\begin{exmp} \label{ex: my example}
my example
\end{exmp}
example : \ref{ex: my example}
\end{document}