嵌套定理标签

嵌套定理标签

我如何定义定理环境以便得到以下行为:

在此处输入图片描述

生成示例的代码:

\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环境连续编号-- 12等--每次出现新的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作为前缀,同时在遇到或环境时仍然执行重置,您仍应删除指令,但现在应该将其替换为propositionquestionpropositionquestion\renewcommand{\thereflection}{}

    \usepackage{etoolbox}
    \AtBeginEnvironment{proposition}{\counterwithin{reflection}{proposition}}
    \AtBeginEnvironment{question}{\counterwithin{reflection}{question}}
    
  • 顺便说一句,如果您希望每次通过指令增加计数器时重置proposition和计数器,您应该更改questionsection\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}

在此处输入图片描述

如果您想添加propositionquestion数字,则会稍微复杂一些。

\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}

在此处输入图片描述

相关内容