我需要显示定理、引理等的编号,如下所示:
定理 3.5.2(第 3 章第 5 节定理 2)。
欲了解更多信息,请访问使用 mdframed 制作定理、引理和证明的精美方框
我怎样才能做到这一点?
平均能量损失
\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}}
答案1
可以使用以下 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}
与原始代码相比,我所做的更改是:
原来的:\renewcommand{\thethm}{\arabic{chapter}.\arabic{thm}}
更改:\renewcommand{\thethm}{\arabic{chapter}.\arabic{section}.\arabic{thm}}
如您所见,我只是简单地添加了\arabic{section}
编号方案。其他编号方案可以相应地进行自定义。
答案2
我会避免在定义中硬连线标签:明确的\label
命令似乎更可取。
\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}