1

I need to show the numbering of Theorems, Lemmas,... as follows:

Theorem 3.5.2 (Theorem 2 in section 5 in chapter 3).

Fore more information, you can visit Fancy boxes for theorem, lemma, and proof with mdframed

How can I do that?

MWE

\newcounter{thm}[chapter]\setcounter{thm}{0}
\renewcommand{\thethm}{\arabic{chapter}.\arabic{thm}}
\newenvironment{thm}[2][]{%
\refstepcounter{thm}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Theorem~\thethm};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Theorem~\thethm:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=green!20,%
linewidth=3pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
\label{#2}}{\end{mdframed}}
0

The requested numbering scheme can be achieved using the code in the following MWE:

\documentclass{scrreprt}

\usepackage{mdframed}
\usepackage{tikz}

\newcounter{thm}[chapter]\setcounter{thm}{0}
\renewcommand{\thethm}{\arabic{chapter}.\arabic{section}.\arabic{thm}}
\newenvironment{thm}[2][]{%
\refstepcounter{thm}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Theorem~\thethm};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Theorem~\thethm:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=green!20,%
linewidth=3pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
\label{#2}}{\end{mdframed}}

\begin{document}

\chapter{test chapter}
\section{test section}
\begin{thm}
some content
\end{thm}

\end{document}

enter image description here

What I changed in comparison to the original code:

Original: \renewcommand{\thethm}{\arabic{chapter}.\arabic{thm}}

Changed: \renewcommand{\thethm}{\arabic{chapter}.\arabic{section}.\arabic{thm}}

As you can see, I have simply added \arabic{section} into the numbering scheme. Other numbering schemes can be customized accordingly.

  • What about \thesection? – Sigur Dec 21 '17 at 12:20
0

I'd avoid hard-wiring the label in the definition: an explicit \label command seems preferable.

\documentclass{book}

\usepackage{tikz}
\usepackage{mdframed}

\newcounter{thm}[section]
\renewcommand{\thethm}{\thesection.\arabic{thm}}

\newenvironment{thm}[1][]
 {%
  \refstepcounter{thm}%
  \mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[anchor=east,rectangle,fill=green!20]{\strut Theorem~\thethm\ifstrempty{#1}{}{:~#1}};%
    },
    innertopmargin=10pt,
    linecolor=green!20,
    linewidth=3pt,
    topline=true,
    frametitleaboveskip=\dimexpr-\ht\strutbox\relax,
  }
  \begin{mdframed}
 }
 {\end{mdframed}}

\begin{document}

\chapter{Main theorems}

\section{Arithmetic}

\begin{thm}\label{A}
$1+1=2$
\end{thm}

\begin{thm}\label{B}
$2+2=4$
\end{thm}

\section{Higher arithmetic}

\begin{thm}[J. de La Palice]\label{C}
$0+0=0$
\end{thm}

\end{document}

enter image description here

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.