GeneralNumbering Paragraph

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
jjvelasco
Posts: 1
Joined: Fri Aug 06, 2021 8:13 pm

Numbering Paragraph

Post by jjvelasco »

I am trying to define an automatic counter for paragraph. The counter starts again every after head. What I need is that the counter continuous with the numeration of a section after I close a subsection within it. I want to improve this implementation:

Code: Select all

\documentclass{article}

\usepackage{lipsum}
\usepackage{etoolbox}

\author{Some One}
\title{Numbered Paragraphs Example}

\newcounter{para}
\newcommand*{\numberedparagraph}{%
  \refstepcounter{para}\thepara.\space
}

\makeatletter

\preto\section{\everypar{}}
\preto\subsection{\everypar{}}
\preto\subsubsection{\everypar{}}

\renewcommand{\@afterheading}{%
  \@nobreaktrue
  \everypar{%
    \if@nobreak
      \@nobreakfalse
      \clubpenalty\@M
      \if@afterindent
      \else
        {\setbox\z@\lastbox}%
      \fi
    \else
      \clubpenalty\@clubpenalty
      \everypar{\numberedparagraph}%
    \fi
    \numberedparagraph
  }%
}

\makeatother

\begin{document}

\maketitle

\section{Sample Section}

\lipsum[1-4]

Some\label{sample} sample text.
\lipsum[5-10]

\subsection{Sample Subsection}

\lipsum[11-15]

\section{Another Section}

\lipsum[16-30]

Cross-reference to paragraph~\ref{sample} on page~\pageref{sample}.

\end{document}
What I need is:

1. Head Section
1.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

2.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

1.1 Hed Subsection
1. XXXXXXXXXXXXXXXXXXXXXXXXXXXXX

2. XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
(end subsection)


3. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

4. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
Sumalatha
Posts: 7
Joined: Tue Sep 28, 2021 6:34 am

Numbering Paragraph

Post by Sumalatha »

So, if you want to number only the main sections and not the subsections, you can use the command \setcounter.

If you are still not clear with this, you can refer to this LaTeX guide and explore the section numbering topic!

You can refer to this - https://typeset.io/resources/learn-late ... t-is-latex
Post Reply