Beschriftung für verschachtelte Theoreme

Beschriftung für verschachtelte Theoreme

Wie kann ich die Theoremumgebungen so definieren, dass ich das folgende Verhalten erhalte:

Bildbeschreibung hier eingeben

Der Code, der das Beispiel generiert:

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

Antwort1

  • Um die reflectionUmgebungen fortlaufend zu nummerieren -- 1, 2, usw. --Undjedes Mal zurückgesetzt werden, wenn entweder eine neue propositionoder questionUmgebung hinzukommt, sollten Sie die Anweisung löschen \renewcommand{\thereflection}{}und durch ersetzen

    \makeatletter
    \@addtoreset{reflection}{proposition}
    \@addtoreset{reflection}{question}
    \makeatother
    

    oder, gleichwertig und auch prägnanter, wie @egreg in einem Kommentar anmerkte,

    \counterwithin*{reflection}{proposition}
    \counterwithin*{reflection}{question}
    

    (Dies funktioniert, weil \counterwithin*{reflection}{proposition}entspricht \makeatletter \@addtoreset{reflection}{proposition} \makeatother.)

  • Um die Nummer der reflectionUmgebung mit dem Präfix entweder der propositionoder der questionNummer (je nachdem, was zuletzt aufgetreten ist) zu versehen und trotzdem immer dann einen Reset auszuführen, wenn eine propositionoder questionUmgebung angetroffen wird, sollten Sie die Anweisung trotzdem löschen \renewcommand{\thereflection}{}, aber jetzt sollten Sie sie durch ersetzen

    \usepackage{etoolbox}
    \AtBeginEnvironment{proposition}{\counterwithin{reflection}{proposition}}
    \AtBeginEnvironment{question}{\counterwithin{reflection}{question}}
    
  • Übrigens, wenn Sie möchten, dass die Zähler propositionund questionjedes Mal zurückgesetzt werden, wenn der sectionZähler über eine Direktive erhöht wird \section, sollten Sie

    \renewcommand{\theproposition}{\thesection.\arabic{proposition}}
    

    Und

    \renewcommand{\thequestion}{\thesection.\arabic{question}}
    

    Zu

    \counterwithin{proposition}{section}
    

    Und

    \counterwithin{question}{section}
    

    bzw. Alternativ können Sie die beiden \renewcommandAnweisungen weglassen und die Anweisungen ändern

    \newtheorem{proposition}{Proposition}
    

    Und

    \newtheorem{question}{Question}
    

    Zu

    \newtheorem{proposition}{Proposition}[section]
    

    Und

    \newtheorem{question}{Question}[section]
    

    jeweils.

Im Übrigen sind die zweite und dritte Instanz von \theoremstyle{definition}in Ihrem Code redundant und könnten (sollten?!) weggelassen werden.

Antwort2

Sie können ganz einfach reflectionnach propositionoder nummerieren 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}

Bildbeschreibung hier eingeben

Etwas komplizierter wird es, wenn man die propositionoder questionZahl hinzufügen möchte.

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

Bildbeschreibung hier eingeben

verwandte Informationen