3

Those days I write a book, and I use framed boxes tcolorbox. Have a look:

\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}

As you can see, I would like to use these frames only for theorems, propositions, lemmas, corollaries and axioms (and not for the definitions). Also I would like to keep the choice to write some of them (for instance, a theorem) without these frames.

My questions are:

  1. How can we have consecutive numbering in the whole text?
  2. Ase you can see, we face a problem with labels in the reference of theorems etc. How can we solve it?

enter image description here

5
  1. The tcbtheorem environments allow you to use counters from other tcbtheorems as well as existing LaTeX counters. It will be easier to define the standard LaTeX theorems first (all sharing the same counter), and then define the tcbtheorems (using that same counter).
  2. The problem is that a label for a tcbtheorem environment needs to be passed as an option to that environment in order for it to work correctly. This is not standard LaTeX behaviour (you would have noticed that labelling and referencing your definition environment would have worked without a hitch).
\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}

Output:

output

As an aside, I would recommend using the cleveref package which can easily be set-up with the each tcbtheorem so as to produce a named reference instead of just a number e.g. 'proposition 1.1.2' vs '1.1.2'. That way you don't have to worry about whether you're referencing a theorem, or a definition, or a proposition etc. each time.

FYI There was a rogue \makeatletter in your code.

  • Works perfect, thank you. But, why \makeatletter is a rogue? – Chris Feb 13 at 22:08
  • 1
    It wasn't doing anything. In general \makeatletter should only be used 'temporarily', being following shortly by \makeatother. – Pippip19 Feb 14 at 6:38
4

The key is the tcolorbox options use counter=<another counter> and use counter from= <counter from another tcolorbox>

Update taking into account the OP comments:

\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}

enter image description here

  • Thank you very much for your comment. It works nice, but I have one more question. How do we refer to a non framed definition or proposition etc? Normally with "\label{}"? – Chris Feb 13 at 21:36
  • 1
    @Chris Do you mean a definition created by a \newtheorem or by a \newtcbtheorem ? – Hafid Boukhoulda Feb 13 at 21:42
  • From newtheorem :) – Chris Feb 13 at 21:42
  • 1
    @Chris \label{mylabel} then \ref{mylabel} where mylabel can be replaced with something like def:commutative ring – Hafid Boukhoulda Feb 13 at 21:51
  • 1
    @Chris answer updated – Hafid Boukhoulda Feb 13 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.