0

I want to create boxes of theorems and lemmas. In addition, there are some commands for definitions and examples. All these commands are related to the document chapter. So far, what I have done is as shown below.

enter image description here

However, I would like the result to be Definition 1.1, Theorem 1.2, Example 1.3, Theorem 1.4, Lemma 1.5. How do I get that? Here is the syntax for the picture above. I really appreciate the help on this.

\documentclass[a4paper,11pt]{book}
\usepackage{charter}
\usepackage[indonesian]{babel}
\usepackage[dvipsnames]{xcolor}
\usepackage{graphicx,amsmath,amssymb,amsthm,amsfonts}
\usepackage{tikz, tkz-euclide}
\usetikzlibrary{calc,through,intersections}
\usepackage{contour}
%\usepackage{amsmath,amssymb}
\usepackage{enumerate}
\usepackage[utf8]{inputenc}
\usepackage[margin=2.5cm]{geometry}
%\usepackage{xcolor}
%\usepackage{graphicx}
\usepackage{capt-of}
%\usepackage{tikz}
%\usepackage[indonesian]{babel}
\usepackage{array,multirow}
%\usepackage{amsmath,amssymb}
\usetikzlibrary{angles}
\usepackage{adjustbox}
\usepackage{epigraph}
\usetikzlibrary{patterns}
\usepackage{systeme}
\usepackage{hyperref}
\usepackage{multicol}
\usepackage{mdframed}
\usepackage[symbol]{footmisc}
\usetikzlibrary{calc}
\let \ds \displaystyle
\let \ds \displaystyle
\renewcommand{\baselinestretch}{1.3}
\parindent.9cm

%-----------------------------CHAP SEC etc..

\usepackage[explicit]{titlesec}
\definecolor{titlebgdark}{RGB}{0,163,243}
\definecolor{titlebglight}{RGB}{191,233,251}
\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}
  {}
  {20pt}
  {%
    \begin{tcolorbox}[
      enhanced,
      colback=black!80,
      boxrule=0.25cm,
      colframe=gray!80,
      arc=0pt,
      outer arc=0pt,
      leftrule=0pt,
      rightrule=0pt,
      fontupper=\color{white}\sffamily\bfseries\huge,
      enlarge left by=-1in-\hoffset-\oddsidemargin, 
      enlarge right by=-\paperwidth+1in+\hoffset+\oddsidemargin+\textwidth,
      width=\paperwidth, 
      left=1in+\hoffset+\oddsidemargin, 
      right=\paperwidth-1in-\hoffset-\oddsidemargin-\textwidth,
      top=0.6cm, 
      bottom=0.6cm,
      overlay={
        \node[
          fill=black!80,
          draw=gray!80,
          line width=0.15cm,
          inner sep=0pt,
          text width=1.7cm,
          minimum height=1.7cm,
          align=center,
          font=\color{white}\sffamily\bfseries\fontsize{30}{36}\selectfont
        ] 
        (chapname)
        at ([xshift=-4cm]frame.north east)
        {\thechapter};
        \node[font=\small,anchor=south,inner sep=2pt] at (chapname.north)
        {\MakeUppercase\chaptertitlename};  % if using amsbook, this should be \chaptername
      } 
    ]
    #1
    \end{tcolorbox}%
  }
\titleformat{name=\chapter,numberless}[display]
  {\normalfont\huge\bfseries}
  {}
  {20pt}
  {%
    \begin{tcolorbox}[
      enhanced,
      colback=black!80,
      boxrule=0.25cm,
      colframe=gray!80,
      arc=0pt,
      outer arc=0pt,
      remember as=title,
      leftrule=0pt,
      rightrule=0pt,
      fontupper=\color{white}\sffamily\bfseries\huge,
      enlarge left by=-1in-\hoffset-\oddsidemargin, 
      enlarge right by=-\paperwidth+1in+\hoffset+\oddsidemargin+\textwidth,
      width=\paperwidth, 
      left=1in+\hoffset+\oddsidemargin, 
      right=\paperwidth-1in-\hoffset-\oddsidemargin-\textwidth,
      top=0.6cm, 
      bottom=0.6cm, 
    ]
    #1
    \end{tcolorbox}%
  }
\titlespacing*{\chapter}
  {0pt}{0pt}{40pt}
\makeatother    
\titleformat{\section}
    {\bfseries\Large\color{black}}{\thesection.}{.5em}{#1}
\titleformat{\subsection}
    {\bfseries\large}{\thesubsection.}{.5em}{#1}
%---------------------------THEOREM STYLE etc..
\usepackage[many]{tcolorbox}
    \tcbuselibrary{skins,breakable}
\usepackage{lmodern}
\newtcolorbox[auto counter, number within=chapter, number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}}]{theorem}[2][]{%
    colback=white,
    enhanced,
    attach boxed title to top left = {xshift=0mm,yshift=-.1mm},
    toprule=1pt, leftrule = 3pt, bottomrule = 1pt, rightrule =1pt,
    arc = 0 mm, sharp corners, colframe=NavyBlue,
    colframe=NavyBlue,colbacktitle=NavyBlue,
    boxed title style = {frame code = { \fill[NavyBlue] (frame.south west)--(frame.north west)--(frame.north east)--([xshift=3mm]frame.east)--(frame.south east)--cycle; 
    \draw[line width=.5mm,NavyBlue]([xshift=2mm]frame.north east)--([xshift=5mm]frame.east)--([xshift=2mm]frame.south east);
            }
    },
    breakable,
    fonttitle=\sffamily\bfseries,
    title=Teorema~\thetcbcounter: #2,
    #1
}

\newtcolorbox[auto counter, number within=chapter, number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}}]{lemma}[2][]{%
    colback=white,
    enhanced,
    attach boxed title to top left = {xshift=0mm,yshift=-.1mm},
    toprule=1pt, leftrule = 3pt, bottomrule = 1pt, rightrule =1pt,
    arc = 0 mm, sharp corners, colframe=purple,
    colframe=purple,colbacktitle=purple,
    boxed title style = {frame code = { \fill[purple] (frame.south west)--(frame.north west)--(frame.north east)--([xshift=3mm]frame.east)--(frame.south east)--cycle; 
    \draw[line width=.5mm,purple]([xshift=2mm]frame.north east)--([xshift=5mm]frame.east)--([xshift=2mm]frame.south east);
            }
    },
    breakable,
    fonttitle=\sffamily\bfseries,
    title=Lemma~\thetcbcounter: #2,
    #1
}


\newtheorem*{remark}{Remark}
\theoremstyle{definition}
\newtheorem{defin}[\tcbcounter]{Definition}
\newtheorem{example}[\tcbcounter]{Example}
\newtheorem{exercise}[\tcbcounter]{Latihan}
\newtheorem{problem}[\tcbcounter]{Soal}
\theoremstyle{remark}


%-----------------------------NEW COMMAND
\newenvironment{solusi}[1][]    {
    \noindent \textit{Solusi.}
    }{}
\newcommand{\theo}[1]{{\bfseries\color{MidnightBlue}\textsf{Teorema #1}}}
\newcommand{\ex}[1]{{\bfseries\color{ForestGreen}\textsf{Contoh #1}}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
%-----------------------------
\begin{document}
\parindent1cm

\chapter{Matriks}
\section{Jangan}
\begin{defin}[Matrix]

\end{defin}
\begin{theorem}{XYZ}
$2+3=5$
\end{theorem}
\begin{theorem}{PQR}
$2-1=1$
\end{theorem}
\begin{example}
$p+q=r$
\end{example}
\begin{theorem}{ABC}
100
\end{theorem}
\begin{lemma}{DEF}
def
\end{lemma}
\end{document}
2
  • 1
    The code you have posted does not compile. Could you post a working example? Jun 28, 2023 at 12:10
  • I have completed the syntax that I wrote. I apologize in advance that I didn't write it from the whole document. Jun 28, 2023 at 13:12

1 Answer 1

2

I would use the theorems library of tcolorbox:

\documentclass[a4paper,11pt]{book}

\usepackage{amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage[many]{tcolorbox}

\newtcbtheorem[number within=chapter]{theorem}{Teorema}{%
    colback=white,
    enhanced,
    attach boxed title to top left = {xshift=0mm,yshift=-.1mm},
    toprule=1pt, leftrule = 3pt, bottomrule = 1pt, rightrule =1pt,
    arc = 0 mm, sharp corners, colframe=NavyBlue,
    colframe=NavyBlue,colbacktitle=NavyBlue,
    boxed title style = {frame code = { \fill[NavyBlue] (frame.south west)--(frame.north west)--(frame.north east)--([xshift=3mm]frame.east)--(frame.south east)--cycle; 
    \draw[line width=.5mm,NavyBlue]([xshift=2mm]frame.north east)--([xshift=5mm]frame.east)--([xshift=2mm]frame.south east);
            }
    },
    breakable,
    fonttitle=\sffamily\bfseries
    }{theo}

\newtcbtheorem[use counter from=theorem]{lemma}{Lemma}{%
    colback=white,
    enhanced,
    attach boxed title to top left = {xshift=0mm,yshift=-.1mm},
    toprule=1pt, leftrule = 3pt, bottomrule = 1pt, rightrule =1pt,
    arc = 0 mm, sharp corners, colframe=purple,
    colframe=purple,colbacktitle=purple,
    boxed title style = {frame code = { \fill[purple] (frame.south west)--(frame.north west)--(frame.north east)--([xshift=3mm]frame.east)--(frame.south east)--cycle; 
    \draw[line width=.5mm,purple]([xshift=2mm]frame.north east)--([xshift=5mm]frame.east)--([xshift=2mm]frame.south east);
            }
    },
    breakable,
    fonttitle=\sffamily\bfseries,
    }{lem}

\newtheorem*{remark}{Remark}
\theoremstyle{definition}
\makeatletter
\newtheorem{defin}[tcb@cnt@theorem]{Definition}
\newtheorem{example}[tcb@cnt@theorem]{Example}
\newtheorem{exercise}[tcb@cnt@theorem]{Latihan}
\newtheorem{problem}[tcb@cnt@theorem]{Soal}
\makeatother

\begin{document}
\chapter{Matriks}
\section{Jangan}
\begin{defin}[Matrix]
some text
\end{defin}
\begin{theorem}{XYZ}{}
$2+3=5$
\end{theorem}
\begin{theorem}{PQR}{}
$2-1=1$
\end{theorem}
\begin{example}
$p+q=r$
\end{example}
\begin{theorem}{ABC}{}
100
\end{theorem}
\begin{lemma}{DEF}{}
def
\end{lemma}
\end{document}

theorems

1
  • It works! Thank you Jun 28, 2023 at 16:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .