1

I want to make sections and subsections in LaTeX also I need in sections I want Thoerem numbers as 1.1. and 1.2 etc.. and, first subsection I want Theorem numbers as 1.1.1 and 1.1.2 In subsection 2 i want to theorem numbers 1.2.1. and 1.2.2. Also in subsection 2, i want add some remarks and corrollary so i need That numbers as 1.2.3 and 1. 2.4. what i do?

2 Answers 2

1

You can play with the LaTeX 2ε-kernel's \@addtoreset.

source2e.pdf says:

\@addtoreset{⟨foo⟩}{⟨bar⟩}: Adds counter ⟨foo⟩ to the list of counters \cl@bar to be reset when counter ⟨bar⟩ is stepped.

For ensuring uniqueness of names of destinations that get placed into the .pdf-file the hyperref-package redefines \@addtoreset to additionally redefine \theH⟨foo⟩ to also deliver the value of ⟨bar⟩ respective \theH⟨bar⟩.

I borrowed DrecksHippy's theoremstyle: :-)

\documentclass[a4paper]{scrartcl}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{amsthm}

\newtheoremstyle{break}
{\topsep}{\topsep}%
{\upshape}{}%
{\bfseries}{}%
{\newline}{}%


\theoremstyle{break}
\newtheorem{MyNiceTheorem}{Theorem}[subsection]% Use subsection to ensure uniqueness of destination-names in case of using hyperref.
\AtBeginDocument{%
  % Let's number theorems within sections and subsections
  \def\theMyNiceTheorem{\ifnum\value{subsection}<1 \thesection\else\thesubsection\fi.\arabic{MyNiceTheorem}}%
  \csname @addtoreset\endcsname{MyNiceTheorem}{section}%
  \csname @addtoreset\endcsname{MyNiceTheorem}{subsection}% <- Do this \@addtoreset as the last one to ensure uniqueness of destination-names in case of using hyperref.
}%

\newtheorem{MyNiceRemark}[MyNiceTheorem]{Remark}
\newtheorem{MyNiceCorollary}[MyNiceTheorem]{Corollary}


\begin{document}
    
    \noindent Cross-referencing:

    \verb|\ref{FirstSectionTheorem}|: \ref{FirstSectionTheorem}

    \verb|\ref{FirstSubSectionTheorem}|: \ref{FirstSubSectionTheorem}

    \verb|\ref{SecondSubSectionTheorem1}|: \ref{SecondSubSectionTheorem1}

    \verb|\ref{SecondSubSectionTheorem2}|: \ref{SecondSubSectionTheorem2}

    \verb|\ref{SecondSectionTheorem}|: \ref{SecondSectionTheorem}

    \verb|\ref{FirstSectionCorollary}|: \ref{FirstSectionCorollary}

    \verb|\ref{FirstSubSectionCorollary}|: \ref{FirstSubSectionCorollary}

    \verb|\ref{SecondSubSectionCorollary1}|: \ref{SecondSubSectionCorollary1}

    \verb|\ref{SecondSubSectionCorollary2}|: \ref{SecondSubSectionCorollary2}

    \verb|\ref{SecondSectionCorollary}|: \ref{SecondSectionCorollary}

    \verb|\ref{FirstSectionRemark}|: \ref{FirstSectionRemark}

    \verb|\ref{FirstSubSectionRemark}|: \ref{FirstSubSectionRemark}

    \verb|\ref{SecondSubSectionRemark1}|: \ref{SecondSubSectionRemark1}

    \verb|\ref{SecondSubSectionRemark2}|: \ref{SecondSubSectionRemark2}

    \verb|\ref{SecondSectionRemark}|: \ref{SecondSectionRemark}


    \noindent\hrulefill

    \section{first section}
    
    \begin{MyNiceTheorem}\label{FirstSectionTheorem}%
        Theorem in first section
    \end{MyNiceTheorem}

    \begin{MyNiceCorollary}\label{FirstSectionCorollary}%
        Corollary in first section
    \end{MyNiceCorollary}

    \begin{MyNiceRemark}\label{FirstSectionRemark}%
        Remark in first section
    \end{MyNiceRemark}

    
    \subsection{first subsection}
    
    \begin{MyNiceTheorem}\label{FirstSubSectionTheorem}%
        Theorem in first subsection
    \end{MyNiceTheorem}

    \begin{MyNiceCorollary}\label{FirstSubSectionCorollary}%
        Corollary in first subsection
    \end{MyNiceCorollary}

    \begin{MyNiceRemark}\label{FirstSubSectionRemark}%
        Remark in first subsection
    \end{MyNiceRemark}

    
    \subsection{second subsection}
    
    \begin{MyNiceTheorem}\label{SecondSubSectionTheorem1}%
        First theorem in second subsection
    \end{MyNiceTheorem}

    \begin{MyNiceCorollary}\label{SecondSubSectionCorollary1}%
        First corollary in second subsection
    \end{MyNiceCorollary}

    \begin{MyNiceRemark}\label{SecondSubSectionRemark1}%
        First remark in second subsection
    \end{MyNiceRemark}


    \begin{MyNiceTheorem}\label{SecondSubSectionTheorem2}%
        Second theorem in second subsection
    \end{MyNiceTheorem}

    \begin{MyNiceCorollary}\label{SecondSubSectionCorollary2}%
        Second corollary in second subsection
    \end{MyNiceCorollary}

    \begin{MyNiceRemark}\label{SecondSubSectionRemark2}%
        Second remark in second subsection
    \end{MyNiceRemark}


    \section{second section}
    
    \begin{MyNiceTheorem}\label{SecondSectionTheorem}%
        Theorem in second section
    \end{MyNiceTheorem}

    \begin{MyNiceCorollary}\label{SecondSectionCorollary}%
        Corollary in second section
    \end{MyNiceCorollary}

    \begin{MyNiceRemark}\label{SecondSectionRemark}%
        Remark in second section
    \end{MyNiceRemark}


\end{document}

enter image description here

1
  • actually I borrowed the the theorem style from egreg he often (maybe always) uses it, when answering theorem related questions and I adopted it for my documents ;) Btw, cool solution Jun 25, 2021 at 8:39
0

You could use two commands to create theorems, one for the theorems below sections and one for the theorems below subsections and set the counters accordingly.

\documentclass[a4paper]{scrartcl}
\usepackage{amsmath}
\usepackage{amsthm}

\newtheoremstyle{break}
{\topsep}{\topsep}%
{\upshape}{}%
{\bfseries}{}%
{\newline}{}%

\theoremstyle{break}
\newtheorem{sectheo}{Theorem}[section]
\newtheorem{subsectheo}{Theorem}[subsection]

\begin{document}
    \section{first section}
    
    \begin{sectheo}
        first section theorem
    \end{sectheo}
    
    \subsection{first subsection}
    
    \begin{subsectheo}
        first subsection theorem
    \end{subsectheo}
    
    \subsection{second subsection}
    
    \begin{subsectheo}
        second subsection theorem
    \end{subsectheo}
\end{document}

enter image description here

4
  • Thank you sir, i follow this code, but in subsection 1.2, i add some lemma and corrollary but the numbers follow like, 1.5 and 1.6, so kindly tell what i do for that?
    – Raa Anand
    Jun 23, 2021 at 17:44
  • In what way you defined Lemma?
    – MadyYuvi
    Jun 23, 2021 at 18:11
  • @RaaAnand As in Ulrich Diez answer you can bind a Lemma's counter to an existing counter by using \newtheorem{<cmd name>}[<counter name>]{<Theorem type>} so for example use \newtheorem{seclemma}[sectheo]{Lemma} for Lemmas within sections. Jun 25, 2021 at 8:29
  • @RaaAnand but as Ulrich Diez answer is more flexible, I'd recommend you use his suggestion Jun 25, 2021 at 8:31

You must log in to answer this question.

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