0

For all my \newtheorems i want the below counting:

when i have for example only a section, i want the counting starts and following the number of section. Next, if i have subsection i want the counting starts and following the number of subsection and so on. how can i do this?

I don't want all the newtheorems follow the "subsection" counting. I want this counting when i have subsection

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 02 '23 at 16:22

1 Answers1

1

You seem to want something like this:

1 Section title A

Some text following.

1.1 Theorem. The statement of the theorem

Some text following.

1.2 Theorem. The statement of the theorem

Some text following.

1.1 Subsection title A

Some text following.

1.1.1 Theorem. The statement of the theorem

Some text following.

1.1.2 Theorem. The statement of the theorem

Some text following.

1.2 Subsection title B

1.2.1 Theorem. The statement of the theorem

2 Section title B

Some text following.

2.1 Theorem. The statement of the theorem

Some text following.

2.2 Theorem. The statement of the theorem

Here's the code.

\documentclass{article}
\usepackage{amsthm}

\newtheorem{theorem}{Theorem}[subsection]% theorem is reset at subsections \counterwithin*{theorem}{section}% theorem is also reset at sections \renewcommand{\thetheorem}{% \ifnum\value{subsection}>0 % we're after \subsection \thesubsection \else % no \subsection came along yet \thesection \fi .\arabic{theorem}% }

\begin{document}

\section{Section title A}

Some text following.

\begin{theorem} The statement of the theorem \end{theorem}

Some text following.

\begin{theorem} The statement of the theorem \end{theorem}

Some text following.

\subsection{Subsection title A}

Some text following.

\begin{theorem} The statement of the theorem \end{theorem}

\begin{theorem} The statement of the theorem \end{theorem}

\subsection{Subsection title B}

Some text following.

\begin{theorem} The statement of the theorem \end{theorem}

\section{Section title B}

Some text following.

\begin{theorem} The statement of the theorem \end{theorem}

Some text following.

\begin{theorem} The statement of the theorem \end{theorem}

\end{document}

enter image description here

Don't. Just use

\newtheorem{theorem}{Theorem}[section]

and your readers will be happier.

egreg
  • 1,121,712