[Tex/LaTex] Numbering sections, subsections etc manually

numberingsectioning

I want to number nested sections, subsections, paragraphs etc manually without using commands like \section{Section},\paragraph{Paragraph} like this:

1
1.1
1.1.1

How can I achieve that?

Best Answer

I'm not sure why you'd want to do this. Even more, I believe you shouldn't discharge the usual commands: if you don't like the appearance of section headings there's the package titlesec that allows for changing them.

Here I propose a \DIV macro that can be called with an optional argument and a mandatory argument for the subdivision level; the optional argument is the number to use (if not specified, just step the normal counter).

\usepackage{xparse}
\NewDocumentCommand{\DIV}{om}{%
  \IfValueT{#1}{\setcounter{#2}{\numexpr#1-1\relax}}%
  \csname #2\endcsname
}

Now you can call

\DIV[42]{section}{The answer to the fundamental question}

and the section will be numbered 42. If the next section is called with

\DIV{section}{Don't panic!}

it will be numbered 43.

Should you want to remove this manual numbering, just comment the \IfValueT line.