22

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?

7
  • 7
    The question is why would you want to do that? One of the advantages of LaTeX is the automated document structure. Could you help us with a full MWE about this document?
    – Aradnix
    Sep 10, 2014 at 6:16
  • 7
    I have a Ferrari and I do have a private racing circuit. Can I drive my Ferrari at 30km/h limit there? Yes, you can, but honestly expect lot of people will ask you "Why?" (in the best case) ;) Sep 10, 2014 at 6:39
  • Of course you can do that -- Now just type in the numbers and the section headings etc, write a toc entry... your text then add a subsection (the number, heading, text,toc) ... add another subsection (number,heading,text,toc)... And now you realize that you have forgotten a subsection between the first two... hm, all the numbers change now... do it manually ... ;-)
    – user31729
    Sep 10, 2014 at 6:50
  • It depends. Do you just want to suppress the default number in the section title, or do you want all equation and theorem numbers etc and the header to reflect the manual number you've chosen? Note that if there's a particular change you want to make (e.g. skip a number or start at zero) it's easier to achieve these directly than number things yourself. Sep 10, 2014 at 9:19
  • 2
    @Adam: Perhaps you should show us a small, working example and there might be suggestions on that, about approaches etc.
    – user31729
    Sep 10, 2014 at 11:26

3 Answers 3

14

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.

0
36

If it's an ad hoc document and you just want the section numbers to match whatever documents the notes are for, a simple solution is to use the * form to suppress numbers and add them as part of the title

\section*{1.24.33 my title} 


\section*{2.3 my next title}

\section*{1.33 my numbers aren't in order} 
1
  • 1
    This is simple but effective, and I suspect catches the use case. Of course if you need a table of contents in your commentary document you'll need a lot of \addcontentslines.
    – Chris H
    Sep 10, 2014 at 14:25
35

It can be a bit frustrating if the only answers to "How do I do that?" are "Don't." Especially if it's very easy to do what you want (and I can imagine use cases). A bit of researching in the internet (https://en.wikibooks.org/wiki/LaTeX/Counters) shows that the command you are looking for is \setcounter{section}{23}, where 23 is the number you want to set it to.

So you'd have something like

\setcounter{section}{23}
\section{My great section}

And it will output "My great section" with number 24, as \section further increases the counter. Works the same for subsection and so on.

4
  • I don't think, that this answers the question
    – user31729
    Sep 10, 2014 at 11:26
  • 2
    @ChristianHupfer, apparently it does, since egregs expanded version on my version has been accepted.
    – Turion
    Sep 10, 2014 at 12:55
  • 1
    Thank you! I was just looking for this, to skip some numbers in the toc, to make it correspond to the content that is already enumerated. It wouldn't look nice to have "Item 5" with subsections like 3.a, 3.b, etc. :-)
    – Kusavil
    Jan 8, 2017 at 13:26
  • It did not work if I set the counter to 0 to me. Dec 20, 2022 at 23:00

You must log in to answer this question.

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