ネストされた定理ラベル

ネストされた定理ラベル

次のような動作が得られるように定理環境を定義するにはどうすればよいでしょうか。

ここに画像の説明を入力してください

例を生成するコード:

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

    それぞれ。あるいは、2つの\renewcommand文を削除し、

    \newtheorem{proposition}{Proposition}
    

    そして

    \newtheorem{question}{Question}
    

    \newtheorem{proposition}{Proposition}[section]
    

    そして

    \newtheorem{question}{Question}[section]
    

    それぞれ。

\theoremstyle{definition}ちなみに、コード内のの 2 番目と 3 番目のインスタンスは冗長であり、省略できます (省略すべき?!)。

答え2

またはreflectionに従って簡単に番号付けできます。propositionquestion

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

ここに画像の説明を入力してください

関連情報