
次のような動作が得られるように定理環境を定義するにはどうすればよいでしょうか。
例を生成するコード:
\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}
それぞれ。あるいは、2つの
\renewcommand
文を削除し、\newtheorem{proposition}{Proposition}
そして
\newtheorem{question}{Question}
に
\newtheorem{proposition}{Proposition}[section]
そして
\newtheorem{question}{Question}[section]
それぞれ。
\theoremstyle{definition}
ちなみに、コード内のの 2 番目と 3 番目のインスタンスは冗長であり、省略できます (省略すべき?!)。
答え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}