11

I want to write both the theorems and definitions (numbering should be chapter-wise, like 2.1, 2.2 etc) in the form of the attached jpg file. enter image description here

EDIT:

In the upper box only the title will come and within the box, the theorem/definition number will come. What to do?

I get a code in internet. I don't know how to modify it. Please help.

\documentclass{article}
\usepackage{amsmath}
\usepackage{cleveref}
\usepackage[most]{tcolorbox}
\newtcbtheorem{Theorem}{Theorem}{
  enhanced,
  sharp corners,
  attach boxed title to top left={
    yshifttext=-1mm
  },
  colback=white,
  colframe=blue!75!black,
  fonttitle=\bfseries,
  boxed title style={
    sharp corners,
    size=small,
    colback=blue!75!black,
    colframe=blue!75!black,
  } 
}{thm}
\newtcbtheorem[no counter]{Proof}{Proof}{
  enhanced,
  sharp corners,
  attach boxed title to top left={
    yshifttext=-1mm
  },
  colback=white,
  colframe=blue!25,
  fonttitle=\bfseries,
  coltitle=black,
  boxed title style={
    sharp corners,
    size=small,
    colback=blue!25,
    colframe=blue!25,
  } 
}{prf}

\begin{document}
\begin{Theorem}{}{fermat}
  No three positive integers \(a\), \(b\) and \(c\) satisfy the equation \(a^{n}
  + b^{n} = c^{n}\) for any integer greater than two.
\end{Theorem}
\begin{Proof}{Theorem \ref{thm:fermat}}{}
  The proof is easy, but too large to fit in this box.
\end{Proof}
\end{document}

Edit 2: Only the problem is in setting counter. Theorem should come 1.1, 1.2 ... and definition should come same as 1.1, 1.2 ....

\documentclass{book}
\usepackage{amsmath}
\usepackage[most]{tcolorbox}
\usepackage{cleveref}

\tcbset{theostyle/.style={
    enhanced,
    sharp corners,
    attach boxed title to top left={
      xshift=-1mm,
      yshift=-4mm,
      yshifttext=-1mm
    },
    top=1.5ex,
    colback=white,
    colframe=blue!75!black,
    fonttitle=\bfseries,
    boxed title style={
      sharp corners,
    size=small,
    colback=blue!75!black,
    colframe=blue!75!black,
  } 
}}

\newtcbtheorem[number within=chapter]{Theorem}{Theorem}{%
  theostyle
}{thm}

\newtcbtheorem[number within=chapter]{Definition}{Definition}{%
  theostyle
}{def}
\newenvironment{myTheorem}[2]{ \begin{Theorem}[adjusted title=#1]{}{#2} 
  \textbf{Theorem \thetcbcounter.} }{\end{Theorem}}
\newenvironment{myDefinition}[2]{ \begin{Theorem}[adjusted title=#1]{}{#2} 
  \textbf{Definition \thetcbcounter.} }{\end{Theorem}}
\begin{document}

\chapter{Foo chapter}

\begin{myDefinition}{ggggggggg}{ReadingTheManual}
  Reading the manual helps ;-)
\end{myDefinition}

\begin{myTheorem}{fffff}{fermat}
  No three positive integers \(a\), \(b\) and \(c\) satisfy the equation \(a^{n}
  + b^{n} = c^{n}\) for any integer greater than two.
\end{myTheorem}
\end{document}
1
  • 3
    Numbering within chapters when using article class? ;-)
    – user31729
    May 12, 2017 at 15:24

2 Answers 2

11
+50
\documentclass{book}
\usepackage{amsmath}
\usepackage{cleveref}
\usepackage[most]{tcolorbox}

\newtcbtheorem[number within=chapter]{Theorem}{}{
        enhanced,
        sharp corners,
        attach boxed title to top left={
            xshift=-1mm,
            yshift=-5mm,
            yshifttext=-1mm
        },
        top=1.5em,
        colback=white,
        colframe=blue!75!black,
        fonttitle=\bfseries,
        boxed title style={
            sharp corners,
            size=small,
            colback=blue!75!black,
            colframe=blue!75!black,
        } 
    }{thm}

\newtcbtheorem[number within=chapter]{Definition}{}{
        enhanced,
        sharp corners,
        attach boxed title to top left={
            xshift=-1mm,
            yshift=-5mm,
            yshifttext=-1mm
        },
        top=1.5em,
        colback=white,
        colframe=blue!75!black,
        fonttitle=\bfseries,
        boxed title style={
            sharp corners,
            size=small,
            colback=blue!75!black,
            colframe=blue!75!black,
        } 
    }{def}

\newenvironment{myTheorem}[2]{ \begin{Theorem}[adjusted title=#1]{}{#2} 
  \textbf{Theorem \thetcbcounter.} }{\end{Theorem}}

  \newenvironment{myDefinition}[2]{ \begin{Definition}[adjusted title=#1]{}{#2} 
  \textbf{Definition \thetcbcounter.} }{\end{Definition}}

\begin{document}
\chapter{Foo}
\begin{myTheorem}{Fermats Last Theorem}{thm:FermatsLastTheorem}
    No three positive integers \(a\), \(b\) and \(c\) satisfy the equation \(a^{n} + b^{n} = c^{n}\) for any integer greater than two.
\end{myTheorem}
\begin{myDefinition}{Reading the Manual}{def:ReadingTheManual}
  Reading the manual helps ;-)
\end{myDefinition}
\begin{myDefinition}{Definition}{def:Definition}
  A statement of the meaning of a word, phrase, or term, as in a dictionary entry.
\end{myDefinition}
\begin{myTheorem}{Pythagoras Theorem}{thm:PythagorasTheorem}
    In a right angled triangle: the square of the hypotenuse is equal to the sum of the squares of the other two sides.
\end{myTheorem}
\end{document}

enter image description here

4
  • This is what exactly I want. Only problem is that the Definition which would come 1.1, 1.2 ... be included. Please modify the code to get this in addition. May 15, 2017 at 3:50
  • I have edited my post above and my modified code has a problem is setting counter in Th and Def May 15, 2017 at 6:12
  • @user1942348 I included the Definition environment.
    – Georg
    May 15, 2017 at 14:07
  • How would you use \ref{} now?
    – xotix
    Jul 8, 2021 at 11:38
9

Use the number within=chapter 'init' option of the \newtcbtheorem macro to apply chapter-wise counting of theorems defined with this macro. (See sections 5 and 16 of the tcolorbox manual for more information on the init option.)

The box style can be changed by using the xshift and yshift keys of attach boxed title to top left.

\documentclass{book}
\usepackage{amsmath}
\usepackage[most]{tcolorbox}
\usepackage{cleveref}

\tcbset{theostyle/.style={
    enhanced,
    sharp corners,
    attach boxed title to top left={
      xshift=-1mm,
      yshift=-4mm,
      yshifttext=-1mm
    },
    top=1.5ex,
    colback=white,
    colframe=blue!75!black,
    fonttitle=\bfseries,
    boxed title style={
      sharp corners,
    size=small,
    colback=blue!75!black,
    colframe=blue!75!black,
  } 
}}

\newtcbtheorem[number within=chapter]{Theorem}{Theorem}{%
  theostyle
}{thm}

\newtcbtheorem[number within=chapter]{Definition}{Definition}{%
  theostyle
}{def}


\begin{document}

\chapter{Foo chapter}

\begin{Definition}{}{ReadingTheManual}
  Reading the manual helps ;-)
\end{Definition}

\begin{Theorem}{}{fermat}
  No three positive integers \(a\), \(b\) and \(c\) satisfy the equation \(a^{n}
  + b^{n} = c^{n}\) for any integer greater than two.
\end{Theorem}
\end{document}

enter image description here

7
  • When I run, I am getting error. File shellesc.sty not found and unable to install it. Also I don't need the proof box. I need def box also and modify the box style as I gave it the jpg file. Please help. May 12, 2017 at 15:33
  • @user1942348: Well, if you don't need the proof, omit it. The definition box can be done in the same way.
    – user31729
    May 12, 2017 at 15:35
  • Also How to modify the box style as I gave it the jpg file May 12, 2017 at 15:42
  • @user1942348: Now it is there. The shellesc.sty is just a matter of installation -- there's nothing I can do for that.
    – user31729
    May 12, 2017 at 15:47
  • Thank you for your effort. In the upper box only the title will come and within the box, the theorem/definition number will come. What to do? May 12, 2017 at 15:49

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.