TransWikia.com

Automatic Paragraph Numbers (everypar only for paragraphs and not for section and so on)

TeX - LaTeX Asked on January 11, 2021

I want to write a specification and each paragraph should automatically be numbered. I found something similar in a book about fitness training:

enter image description here

I prepared a small MWE (two-sided layout):

documentclass{book}

usepackage[english]{babel}
usepackage[toc]{blindtext}

begin{document}

Blinddocument

end{document}

Sadly I do not have a starting point for a solution. A manual solution would be to use margin notes.

Ideally the solution does not include a command I have to write before
every paragraph.

Update 1

Question/Answer Numbered paragraphs is pretty close:

documentclass{article}
usepackage[excludeor]{everyhook}
usepackage{lipsum}
usepackage{parskip} % I added this, Manuel Kuehner
newcounter{paragraphs}[section]
begin{document}
PushPostHook{par}{%
        stepcounter{paragraphs}%
        llap{thesection.theparagraphs kernparindent}%
}
section{Foo}
lipsum
section{Bar}
lipsum
end{document}

It creates an output like this:

enter image description here

So the output is not correct.

The problem is here that every section etc. also gets the additional
numbering.

Update 2

Here’s another close solution (in German): http://texwelt.de/wissen/fragen/5020

But there’s the same problem that I need to use a command for every number.

Update 3 [2020-11-07, i. e. 5 Years later]

  • After using/trying this for about 1.5 years I stopped it.
  • In hindsight, the comments (@egreg for example) were right and it used too many unwanted side effects.
  • I am sorry that I do not have a better update.
  • I ended up using subsubparagraph and used it for every paragraph with a different formatting compared to the rest of the headings.

2 Answers

One approach using the linguex package:

enter image description here

documentclass{article}
usepackage{lipsum} % for dummy text    
usepackage{linguex}
% Counter format 
renewcommand{ExLBr}{bfseries}
renewcommand{ExRBr}{}
% http://tex.stackexchange.com/a/57279/11604
% Reset ex. at each section 
usepackage{chngcntr}
counterwithin{ExNo}{section}
% add section counter
renewcommand{Exarabic}{thesection.arabic} 
begin{document}
section{First section}
ex. lipsum[2]par
ex. lipsum[3]par
section{Second section}
ex. lipsum[3]par
end{document}

Edit: If yo do not want any command starting the paragraphs, use everypar at your own risk ... you are warned in the comments.

In the next MWE, the macro NumPar at the beginning of each section produce the same output that above. As example of the problems about using everypar, note that a new section cancel the numeration but do not restore the default indentation of 1em, so you must restore it manually.

documentclass{article}
usepackage{lipsum}
parindent1em
begin{document}
defNumPar{%
parskip0.5em%
parindent0em%
everypar={%
hangindent3em%
addtocounter{subsection}{1}%
makebox[3em][l]{bfseriesthesubsection}%
}}%
section{First section}
NumPar
lipsum[2]par
lipsum[3]par
everypar{}
lipsum[3]par
section{Second section}
NumPar % Or parindent1em to return to normal paragraphs
lipsum[3]par
lipsum[3]par
end{document}

Correct answer by Fran on January 11, 2021

Another solution which is non-automatic, but a handy solution is using the enumitem package. Only itemize each paragraph in the description block:

documentclass{article}
usepackage{lipsum} % for dummy text    
usepackage{enumitem}
begin{document}
section{First section}
begin{description}[style=unboxed,leftmargin=0.7cm]
item[$textbf{1.1}$]lipsum[1]par
item[$textbf{1.2}$]lipsum[2]par
end{description}
section{Second section}
begin{description}[style=unboxed,leftmargin=0.7cm]
item[$textbf{2.1}$]lipsum[3]par
end{description}
end{document}

Answered by moksef on January 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP