5

I'd like to have chapter.theorem numbers for an mdframed theorem environment. I can modify the environment definition to include this, as in:

\documentclass{memoir}

\usepackage{amsmath}
\usepackage[english]{cleveref}
\usepackage[svgnames]{xcolor}
\usepackage[framemethod=tikz]{mdframed}

\newcounter{Theorem}[chapter]
\newenvironment{Theorem}[1][]{%
  \refstepcounter{Theorem}%
  \ifstrempty{#1}%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[line width=1pt,anchor=east,rectangle,draw=DarkOliveGreen,fill=white]
    {\strut \color{DarkOliveGreen}{Theorem}~\thechapter.\theTheorem};}}
  }%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[line width=1pt,anchor=east,rectangle,draw=DarkOliveGreen,fill=white]
    {\strut \color{DarkOliveGreen}{Theorem}~\thechapter.\theTheorem:~\color{Maroon}{#1}};}}%
  }%
  \mdfsetup{innertopmargin=10pt,linecolor=DarkOliveGreen,%
            linewidth=1pt,topline=true,%
            frametitleaboveskip=\dimexpr-\ht\strutbox\relax,}
  \begin{mdframed}[]\relax%
  }{\end{mdframed}}

\crefname{Theorem}{theorem}{theorems} 
\Crefname{Theorem}{Theorem}{Theorems} 

\begin{document}

\chapter{blah}

\begin{Theorem}[Distribution of inner products]\label{thm:stokesTheoremGeometricAlgebraII:1420}
Given two blades $A_s, B_r$ with grades subject to $0 < r < s$, and a vector $b$, the inner product distributes according to
\begin{equation*}
    A_s \cdot \left( b \wedge B_r \right) = \left( A_s \cdot b \right) \cdot B_r.
\end{equation*}
\end{Theorem}

Reference to \cref{thm:stokesTheoremGeometricAlgebraII:1420}.

\end{document}

To get cleveref to find the label, this was modified to use refstepcounter instead of stepcounter as shown in cleveref-doesnt-find-the-label. This produces:

cref to fix

How can I modify things so that the cref output shows up as 'theorem 1.1' (i.e. including the chapter number as in the theorem title text)?

2

Since you are already loading amsmath, you can say

\newcounter{Theorem}
\numberwithin{Theorem}{chapter}

A complete example:

\documentclass{memoir}

\usepackage{amsmath}
\usepackage[english]{cleveref}
\usepackage[svgnames]{xcolor}
\usepackage[framemethod=tikz]{mdframed}

\newcounter{Theorem}
\numberwithin{Theorem}{chapter}
\newenvironment{Theorem}[1][]{%
  \refstepcounter{Theorem}%
  \ifstrempty{#1}%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[line width=1pt,anchor=east,rectangle,draw=DarkOliveGreen,fill=white]
    {\strut \color{DarkOliveGreen}{Theorem}~\theTheorem};}}
  }%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[line width=1pt,anchor=east,rectangle,draw=DarkOliveGreen,fill=white]
    {\strut \color{DarkOliveGreen}{Theorem}~\theTheorem:~\color{Maroon}{#1}};}}%
  }%
  \mdfsetup{innertopmargin=10pt,linecolor=DarkOliveGreen,%
            linewidth=1pt,topline=true,%
            frametitleaboveskip=\dimexpr-\ht\strutbox\relax,}
  \begin{mdframed}[]\relax%
  }{\end{mdframed}}

\crefname{Theorem}{theorem}{theorems} 
\Crefname{Theorem}{Theorem}{Theorems} 

\begin{document}

\chapter{blah}

\begin{Theorem}[Distribution of inner products]\label{thm:stokesTheoremGeometricAlgebraII:1420}
Given two blades $A_s, B_r$ with grades subject to $0 < r < s$, and a vector $b$, the inner product distributes according to
\begin{equation*}
    A_s \cdot \left( b \wedge B_r \right) = \left( A_s \cdot b \right) \cdot B_r.
\end{equation*}
\end{Theorem}

Reference to \cref{thm:stokesTheoremGeometricAlgebraII:1420}.

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