我有以下盒装环境,我想添加节编号。它应该显示“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}