0

I'm not very familiar to Latex. The numbering of my theorems, definitions, remarks etc. appears like 1.0.0.1 for first definition. I don't want zeroes to appear if there are no subsections or subsubsections. Here is what Have in preamble

\documentclass[12pt]{article}
\usepackage{amsthm,amsmath}
\usepackage{amscd}
\usepackage{hyperref}
\usepackage[all]{xypic}
\usepackage{mathtools}
\usepackage{xcolor}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,mathrsfs}
\usepackage{hyperref}
\usepackage[all]{xypic}
\usepackage{times}
\usepackage{inputenc}
\usepackage{lipsum}
\usepackage{titlesec}
\DeclareUnicodeCharacter{0308}{HERE!HERE!}
\setcounter{MaxMatrixCols}{10}

\newtheorem{lemma}{Lemma}[subsubsection]
\newtheorem{corollary}[lemma]{Corollary}
\newtheorem{fact}[lemma]{Fact}
\newtheorem{theorem}[lemma]{Theorem}
\newtheorem{proposition}[lemma]{Proposition}
\newtheorem{definition}[lemma]{Definition}
\newtheorem{remark}[lemma]{Remark}
\newtheorem{example}[lemma]{Example}
\newtheorem{examples}[lemma]{Examples}
\newtheorem{question}[lemma]{Question}

Please help.

Edit: In my first section (for example), there is no subsection, so I want numbering as 1.1, 1.2 and so on and not as 1.0.0.1, 1.0.0.2 etc. In my second section I have a subsection but no subsubsection, there I want theorem numbering to be like "Theorem 2.1.1" and so on. I want four-digit numbering to start when there is a subsubsection". I hope my question is clear now.

3
  • 1
    lacking a clear idea of what you want, you may try to say \newtheorem{lemma}{Lemma}[section] and see if this is what you expect.
    – Denis
    Nov 22, 2022 at 6:11
  • Off-topic: Don't load xypic and hyperref twice. Nothing good will come out of such duplication.
    – Mico
    Nov 22, 2022 at 6:14
  • \newthorem{lemma}{Lemma}[section] gives a numbering which ignores subsection numbers. I want subsection and subsubsection numbers to be included in theorem numbering. The problem is that in my first section, I don't have any subsection, as a result my first definition gets numbered as "Definition 1.0.0.1" instead of only "Definition 1.1."
    – Ashraf
    Nov 22, 2022 at 7:23

1 Answer 1

1

I really would not encourage this way of doing. But quick and dirty you may try

\documentclass[12pt]{article}
\usepackage{amsthm}
\usepackage{mathtools}
\newtheorem{lemma}{Lemma}[subsubsection]
\newcounter{lemmaaux}
\setcounter{lemmaaux}{0}
\begin{document}
\section{first}
\counterwithin{lemma}{section}
\begin{lemma}\addtocounter{lemmaaux}{1}
My nice lemma
\end{lemma}
\subsection{The fist sub}
\counterwithin{lemma}{subsection}\setcounter{lemma}{\thelemmaaux}
\begin{lemma}\addtocounter{lemmaaux}{1}
My nice second lemma
\end{lemma}
\subsubsection{The fist subsub}
\counterwithin{lemma}{subsubsection}\setcounter{lemma}{\thelemmaaux}
\begin{lemma}\addtocounter{lemmaaux}{1}
My new lemma
\end{lemma}
\section{second}
\counterwithin{lemma}{section}\setcounter{lemma}{\thelemmaaux}
\begin{lemma}\addtocounter{lemmaaux}{1}
My nice third lemma
\end{lemma}
\subsection{The second sub}
\counterwithin{lemma}{subsection}\setcounter{lemma}{\thelemmaaux}
\begin{lemma}\addtocounter{lemmaaux}{1}
My nice fourth lemma
\end{lemma}
\end{document} 

enter image description here

5
  • Although it may be a dirty way as you said , it partially worked for me. However, you didn't mentioned about subsection of a subsection i.e. subsubsection.
    – Ashraf
    Nov 22, 2022 at 9:53
  • see my edit. please consider accepting the answer if you think it is useful.
    – Denis
    Nov 22, 2022 at 9:58
  • Your edit has created some more problem. For example, in your "first sub" the numbering should restart from 1 i.e., Lemma 1.1.1 and not Lemma 1.1.2. Accordingly in "first subsub" it should appear as Lemma1.1.1.1 and not Lemma1.1.1.3.
    – Ashraf
    Nov 22, 2022 at 10:32
  • I guess what you want is unclear to me. Anyhow, you have now the nuts and bolts.
    – Denis
    Nov 22, 2022 at 10:37
  • Thanks to you. I managed to do what I wanted with sufficient hints from your answer. Im accepting it as answer.
    – Ashraf
    Nov 22, 2022 at 10:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .