Most output formats support an option number_sections
, which can be used to enable numbering sections if set to true
, e.g.,
output:
html_document:
number_sections: true
pdf_document:
number_sections: true
If you want a certain section to be unnumbered when the option number_sections
is true
, you may add {-}
after the section heading, e.g.,
# This section is unnumbered {-}
Equivalently, you may also use {.unnumbered}
. You can also add other attributes to the heading, e.g., {.unnumbered #section-id}
. Please see https://pandoc.org/MANUAL.html#extension-header_attributes for more information.
Unnumbered sections are often used for providing extra information about the writing. For example, for this book, the chapters “Preface” and “About the Authors” are unnumbered, since they do not belong to the body of this book. As you may see in Figure 4.1, the actual body starts after the two unnumbered chapters, and the chapters in the book body are numbered.
Section numbers are incremental. If you insert an unnumbered section after a numbered section, and then start another numbered section, the section number will resume incrementing.