为盒装环境添加章节编号

为盒装环境添加章节编号

我有以下盒装环境,我想添加节编号。它应该显示“Bevis #.#”,而不是“Bevis”。

我目前拥有的图像
帮助

我正在使用的代码

\documentclass{report}  
\usepackage{amsthm}  
\usepackage[framemethod=tikz]{mdframed}  
\usepackage{lipsum}  

\newtheoremstyle{bev}  
  {\topsep}%  
  {\topsep}%  
  {\normalfont}%  
  {}%  
  {\bfseries}%  
  {:}%  
  {.5em}%  
  {\thmname{#1}\thmnote{~(#3)}}%  
\theoremstyle{bev}  
\newmdtheoremenv[  
hidealllines=true,  
innertopmargin=0pt,  
linewidth=4pt,  
linecolor=gray!40,  
singleextra={  
  \draw[line width=3pt,gray!50,line cap=rect] (O|-P) -- +(1cm,0pt);  
  \draw[line width=3pt,gray!50,line cap=rect] (O|-P) -- +(0pt,-1cm);  
  \draw[line width=3pt,gray!50,line cap=rect] (O-|P) -- +(-1cm,0pt);  
  \draw[line width=3pt,gray!50,line cap=rect] (O-|P) -- +(0pt,1cm);  
  },  
firstextra={  
  \draw[line width=3pt,gray!50,line cap=rect] (O|-P) -- +(1cm,0pt);  
  \draw[line width=3pt,gray!50,line cap=rect] (O|-P) -- +(0pt,-1cm);  
},  
secondextra={  
  \draw[line width=3pt,gray!50,line cap=rect] (O-|P) -- +(-1cm,0pt);  
  \draw[line width=3pt,gray!50,line cap=rect] (O-|P) -- +(0pt,1cm);  
}  
]{bev}{Bevis}  

\begin{document}  

\begin{bev}  
\lipsum[4]  
\end{bev}  

\end{document}  

任何帮助都将不胜感激!

答案1

mdframed包及其\newmdframedtheoremenv命令的工作原理基本上类似于\newtheorem,可以添加一个重置计数器,它在section这里(根据要求)。

但使用chapters通常的\thesection命令会有\thechapter.\arabic{section},因此\thebev应该将命令重新定义为\arabic{section}.\arabic{bev}

要查看数字,请\thmnumber{#2}在定理样式的定义中使用(它是的最后一个参数\newtheoremstyle

\documentclass{report}  
\usepackage{amsthm}  
\usepackage[framemethod=tikz]{mdframed}  
\usepackage{lipsum}  


\newtheoremstyle{bev}  
  {\topsep}%  
  {\topsep}%  
  {\normalfont}%  
  {}%  
  {\bfseries}%  
  {:}%  
  {.5em}%  
  {\thmname{#1} \thmnumber{#2}\thmnote{~(#3)}}%  
\theoremstyle{bev}  
\newmdtheoremenv[  
hidealllines=true,  
innertopmargin=0pt,  
linewidth=4pt,  
linecolor=gray!40,  
singleextra={  
  \draw[line width=3pt,gray!50,line cap=rect] (O|-P) -- +(1cm,0pt);  
  \draw[line width=3pt,gray!50,line cap=rect] (O|-P) -- +(0pt,-1cm);  
  \draw[line width=3pt,gray!50,line cap=rect] (O-|P) -- +(-1cm,0pt);  
  \draw[line width=3pt,gray!50,line cap=rect] (O-|P) -- +(0pt,1cm);  
  },  
firstextra={  
  \draw[line width=3pt,gray!50,line cap=rect] (O|-P) -- +(1cm,0pt);  
  \draw[line width=3pt,gray!50,line cap=rect] (O|-P) -- +(0pt,-1cm);  
},  
secondextra={  
  \draw[line width=3pt,gray!50,line cap=rect] (O-|P) -- +(-1cm,0pt);  
  \draw[line width=3pt,gray!50,line cap=rect] (O-|P) -- +(0pt,1cm);  
}  
]{bev}{Bevis}[section]

\renewcommand{\thebev}{\arabic{section}.\arabic{bev}}

\begin{document}  

\chapter{Foo chapter}
\section{Foo 1}
\begin{bev}  
\lipsum[4]  
\end{bev}  

\section{Foo 2}
\begin{bev}  
\lipsum[4]  
\end{bev}  


\end{document}  

在此处输入图片描述

答案2

您可以创建一个新的计数器\newcounter{bevCounter}。用 设置计数器增量\refstepcounter{bevCounter}。计数器值为\thebevCounter

通过添加,\usepackage{amsmath} 您可以用来\numberwithin{bevCounter}{section}定义章节编号。

在此处输入图片描述

代码:

\documentclass{report}
\usepackage{amsthm}  
\usepackage[framemethod=tikz]{mdframed}  
\usepackage{lipsum}  


\newcounter{bevCounter} 

\newtheoremstyle{bev}  
  {\topsep}%  
  {\topsep}%  
  {\normalfont}%  
  {}%  
  {\bfseries}%  
  {:}%  
  {.5em}%  
  {\thmname{#1}\thmnote{~(#3)}}%  
\theoremstyle{bev}  
\newmdtheoremenv[  
hidealllines=true,  
innertopmargin=0pt,  
linewidth=4pt,  
linecolor=gray!40,  
singleextra={  
  \draw[line width=3pt,gray!50,line cap=rect] (O|-P) -- +(1cm,0pt);  
  \draw[line width=3pt,gray!50,line cap=rect] (O|-P) -- +(0pt,-1cm);  
  \draw[line width=3pt,gray!50,line cap=rect] (O-|P) -- +(-1cm,0pt);  
  \draw[line width=3pt,gray!50,line cap=rect] (O-|P) -- +(0pt,1cm);  
  },  
firstextra={  
  \draw[line width=3pt,gray!50,line cap=rect] (O|-P) -- +(1cm,0pt);  
  \draw[line width=3pt,gray!50,line cap=rect] (O|-P) -- +(0pt,-1cm);  
},  
secondextra={  
  \draw[line width=3pt,gray!50,line cap=rect] (O-|P) -- +(-1cm,0pt);  
  \draw[line width=3pt,gray!50,line cap=rect] (O-|P) -- +(0pt,1cm);  
}  
]{bev}{Bevis \refstepcounter{bevCounter} \thebevCounter}  

\usepackage{amsmath}
\numberwithin{bevCounter}{section}


\begin{document}

\chapter{Chapter}

\section{sec 1}
\begin{bev}  
\lipsum[4]  
\end{bev}  

\begin{bev}  
\lipsum[4]  
\end{bev}  

\section{Two}
\begin{bev}  
\lipsum[4]  
\end{bev}  


\end{document}

相关内容