
¿Cómo puedo definir los entornos de teoremas de modo que obtenga el siguiente comportamiento?
El código que genera el ejemplo:
\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}
Respuesta1
Para que los
reflection
ambientes estén numerados consecutivamente --1
,2
, etc --yrestablecerse cada vez que aparece un entorno nuevo, debe eliminar la instrucciónproposition
y reemplazarla conquestion
\renewcommand{\thereflection}{}
\makeatletter \@addtoreset{reflection}{proposition} \@addtoreset{reflection}{question} \makeatother
o, de manera equivalente y también más sucinta, como lo señala @egreg en un comentario,
\counterwithin*{reflection}{proposition} \counterwithin*{reflection}{question}
(Esto funciona porque
\counterwithin*{reflection}{proposition}
es equivalente a\makeatletter \@addtoreset{reflection}{proposition} \makeatother
).Para que el número del
reflection
entorno tenga el prefijoproposition
o elquestion
número (lo que haya ocurrido más recientemente), mientras se ejecuta un reinicio cada vez que se encuentre un entornoproposition
oquestion
, aún debe eliminar la instrucción\renewcommand{\thereflection}{}
, pero ahora debe reemplazarla con\usepackage{etoolbox} \AtBeginEnvironment{proposition}{\counterwithin{reflection}{proposition}} \AtBeginEnvironment{question}{\counterwithin{reflection}{question}}
Por cierto, si desea que los contadores
proposition
yquestion
se restablezcan cada vez quesection
se incrementa el contador mediante una\section
directiva, debe cambiar\renewcommand{\theproposition}{\thesection.\arabic{proposition}}
y
\renewcommand{\thequestion}{\thesection.\arabic{question}}
a
\counterwithin{proposition}{section}
y
\counterwithin{question}{section}
respectivamente. Alternativamente, elimine las dos
\renewcommand
declaraciones y cámbielas.\newtheorem{proposition}{Proposition}
y
\newtheorem{question}{Question}
a
\newtheorem{proposition}{Proposition}[section]
y
\newtheorem{question}{Question}[section]
respectivamente.
Por cierto, la segunda y tercera instancia de \theoremstyle{definition}
en su código son redundantes y podrían (¡¿deberían?!) omitirse.
Respuesta2
Puede numerar fácilmente reflection
según proposition
o 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}
Es un poco más complicado si desea agregar el número proposition
o 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}