我如何定义定理环境以便得到以下行为:
生成示例的代码:
\documentclass[10pt,a4paper]{article}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{proposition}{Proposition}
\renewcommand{\theproposition}{\thesection.\arabic{proposition}}
\newcommand{\propositionautorefname}{Proposition}
\theoremstyle{definition}
\newtheorem{question}{Question}
\renewcommand{\thequestion}{\thesection.\arabic{question}}
\newcommand{\questionautorefname}{Q.}
\theoremstyle{definition}
\newtheorem{reflection}{Reflection}
\renewcommand{\thereflection}{}
\newcommand{\reflectionautorefname}{Reflection}
\begin{document}
\begin{proposition}
My proposition
\begin{reflection}
My reflection should be numbered 0.1.1. or 1
\end{reflection}
\begin{reflection}
My reflection should be numbered 0.1.2. or 2
\end{reflection}
\end{proposition}
\begin{question}
My question
\begin{reflection}
My reflection should be numbered 0.1.1. or 1
\end{reflection}
\begin{reflection}
My reflection should be numbered 0.1.2. or 2
\end{reflection}
\end{question}
\end{document}
答案1
要使
reflection
环境连续编号--1
,2
等--和每次出现新的proposition
或环境时都要重置,你应该删除该指令并将其替换为question
\renewcommand{\thereflection}{}
\makeatletter \@addtoreset{reflection}{proposition} \@addtoreset{reflection}{question} \makeatother
或者,同样也更简洁,正如@egreg在评论中指出的那样,
\counterwithin*{reflection}{proposition} \counterwithin*{reflection}{question}
(这
\counterwithin*{reflection}{proposition}
是有效的,因为 相当于\makeatletter \@addtoreset{reflection}{proposition} \makeatother
。)为了使环境编号以或数字(以最近发生的为准)
reflection
作为前缀,同时在遇到或环境时仍然执行重置,您仍应删除指令,但现在应该将其替换为proposition
question
proposition
question
\renewcommand{\thereflection}{}
\usepackage{etoolbox} \AtBeginEnvironment{proposition}{\counterwithin{reflection}{proposition}} \AtBeginEnvironment{question}{\counterwithin{reflection}{question}}
顺便说一句,如果您希望每次通过指令增加计数器时重置
proposition
和计数器,您应该更改question
section
\section
\renewcommand{\theproposition}{\thesection.\arabic{proposition}}
和
\renewcommand{\thequestion}{\thesection.\arabic{question}}
到
\counterwithin{proposition}{section}
和
\counterwithin{question}{section}
或者,删除这两个
\renewcommand
语句,然后更改语句\newtheorem{proposition}{Proposition}
和
\newtheorem{question}{Question}
到
\newtheorem{proposition}{Proposition}[section]
和
\newtheorem{question}{Question}[section]
分别。
\theoremstyle{definition}
顺便说一句,代码中的第二和第三个实例是多余的,可以(应该?!)被省略。
答案2
您可以轻松地reflection
按照proposition
或进行编号question
:
\documentclass[10pt,a4paper]{article}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{proposition}{Proposition}[section]
\newcommand{\propositionautorefname}{Proposition}
\newtheorem{question}{Question}[section]
\newcommand{\questionautorefname}{Q.}
\newtheorem{reflection}{Reflection}
\newcommand{\reflectionautorefname}{Reflection}
\counterwithin*{reflection}{proposition}
\counterwithin*{reflection}{question}
\begin{document}
\section{Title}
\begin{proposition}
My proposition
\begin{reflection}
My reflection should be numbered 1
\end{reflection}
\begin{reflection}
My reflection should be numbered 2
\end{reflection}
\end{proposition}
\begin{question}
My question
\begin{reflection}
My reflection should be numbered or 1
\end{reflection}
\begin{reflection}
My reflection should be numbered or 2
\end{reflection}
\end{question}
\end{document}
如果您想添加proposition
或question
数字,则会稍微复杂一些。
\documentclass[10pt,a4paper]{article}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{propositioninner}{Proposition}[section]
\newcommand{\propositioninnerautorefname}{Proposition}
\newenvironment{proposition}
{%
\renewcommand{\PropositionOrQuestion}{\thepropositioninner}%
\propositioninner
}
{\endpropositioninner}
\newtheorem{questioninner}{Question}[section]
\newcommand{\questioninnerautorefname}{Q.}
\newenvironment{question}
{%
\renewcommand{\PropositionOrQuestion}{\thequestioninner}%
\questioninner
}
{\endquestioninner}
\newcommand{\PropositionOrQuestion}{}
\newtheorem{reflection}{Reflection}
\newcommand{\reflectionautorefname}{Reflection}
\counterwithin*{reflection}{propositioninner}
\counterwithin*{reflection}{questioninner}
\renewcommand{\thereflection}{\PropositionOrQuestion.\arabic{reflection}}
\begin{document}
\section{Title}
\begin{proposition}
My proposition
\begin{reflection}
My reflection should be numbered 1.1.1
\end{reflection}
\begin{reflection}
My reflection should be numbered 1.1.2
\end{reflection}
\end{proposition}
\begin{question}
My question
\begin{reflection}
My reflection should be numbered or 1.1.1
\end{reflection}
\begin{reflection}
My reflection should be numbered or 1.1.2
\end{reflection}
\end{question}
\end{document}