使用 mdframed 包(带有[frame-method=tikz]
),我可以创建一个新的环境,使用以下命令重置每个章节
\newmdtheoremenv[<options>]{myenv}[<numberedlike>]{Sample}[chapter]
下面的 MWE 显示了此用法,其中输出“样本”标记为 2.1、2.2 等。如何将编号格式更改为 2-1、2-2 等?
\documentclass{book}
\usepackage{ntheorem}
\usepackage[framemethod=tikz]{mdframed}
\newmdtheoremenv{myenv}{Sample}[chapter]
% or \theoremenv{myenv}{Sample}[chapter]
\begin{document}
\chapter{First chapter}
Chapter content
\chapter{Second chapter}
Chapter content with samples
\begin{myenv}
My first sample
\end{myenv}
\begin{myenv}
My second sample
\end{myenv}
\end{document}
答案1
在序言的某处添加以下几行
\makeatletter
\renewcommand\@thmcountersep{-}
\makeatother
\documentclass{book}
\makeatletter
\renewcommand\@thmcountersep{-}
\makeatother
\usepackage{ntheorem}
\usepackage[framemethod=tikz]{mdframed}
\newmdtheoremenv{myenv}{Sample}[chapter]
\begin{document}
\chapter{First chapter}
Chapter content
\chapter{Second chapter}
Chapter content with samples
\begin{myenv}
My first sample
\end{myenv}
\begin{myenv}
My second sample
\end{myenv}
\end{document}