TeX - LaTeX Asked by robintw on November 27, 2020
I have a document which requires many levels of sectioning. I have sections, subsections and subsubsections, but require one more level below that. I can’t change the sections to be parts and move everything up a level, as this document will eventually be included in another document which has parts/chapters already.
I see that the paragraph
command is used for defining the section level below subsubsection, but that doesn’t produce headings in the same way that subsection and subsubsection do. Is there any way to either (1) change the paragraph
command so that it works like subsubsection but just adds another number – ie. 1.2.3.4 or (2) create a subsubsubsection
command to do the same thing?
You can use the titlesec
package to change the way paragraph
formats the titles and set the secnumdepth
counter to four to obtain numbering for the paragraphs:
documentclass{article}
usepackage{titlesec}
setcounter{secnumdepth}{4}
titleformat{paragraph}
{normalfontnormalsizebfseries}{theparagraph}{1em}{}
titlespacing*{paragraph}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
begin{document}
section{Test Section}
test
subsection{Test Subsection}
test
subsubsection{Test Subsubsection}
test
paragraph{Test Modified Paragraph}
test
end{document}
If you want to define a new sectioning command, you can take a look at Defining custom sectioning commands.
If you want to define a fresh new sectional unit below subsubsection
, but above paragraph
, then you will have to do considerably more work: a new counter has to be created and its representation has to be appropriately defined; the sectional units paragraph
and subparagraph
will also have to be redefined, as well as they corresponding l@...
commands (controlling how the will be typeset in the ToC if the tocdepth
value is increased); also, the toclevel (for eventual bookmarks) will have to be considered.
Here's an example showing how to obtain this new sectional unit giving you now the option to use part
, section
, subsection
, subsubsection
, subsubsubsection
, paragraph
, and subparagraph
:
documentclass{article}
usepackage{titlesec}
usepackage{hyperref}
titleclass{subsubsubsection}{straight}[subsection]
newcounter{subsubsubsection}[subsubsection]
renewcommandthesubsubsubsection{thesubsubsection.arabic{subsubsubsection}}
renewcommandtheparagraph{thesubsubsubsection.arabic{paragraph}} % optional; useful if paragraphs are to be numbered
titleformat{subsubsubsection}
{normalfontnormalsizebfseries}{thesubsubsubsection}{1em}{}
titlespacing*{subsubsubsection}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
makeatletter
renewcommandparagraph{@startsection{paragraph}{5}{z@}%
{3.25ex @plus1ex @minus.2ex}%
{-1em}%
{normalfontnormalsizebfseries}}
renewcommandsubparagraph{@startsection{subparagraph}{6}{parindent}%
{3.25ex @plus1ex @minus .2ex}%
{-1em}%
{normalfontnormalsizebfseries}}
deftoclevel@subsubsubsection{4}
deftoclevel@paragraph{5}
deftoclevel@paragraph{6}
defl@subsubsubsection{@dottedtocline{4}{7em}{4em}}
defl@paragraph{@dottedtocline{5}{10em}{5em}}
defl@subparagraph{@dottedtocline{6}{14em}{6em}}
makeatother
setcounter{secnumdepth}{4}
setcounter{tocdepth}{4}
begin{document}
tableofcontents
section{Test Section}
test
subsection{Test Subsection}
test
subsubsection{Test Subsubsection}
test
subsubsubsection{Test Subsubsubsection}
test
paragraph{Test Paragraph}
test
subparagraph{Test Subparagraph}
test
end{document}
Correct answer by Gonzalo Medina on November 27, 2020
Here's a solution that doesn't require the use of a specialized package such as titlesec
or sectsty
. (There's nothing wrong per se, obviously, with using packages to achieve a certain goal; nevertheless, I think it can be instructive at times to see how one can manipulate some of LaTeX's built-in commands directly.)
If you use the article
document class, the default appearance of the output of the commands subsubsection
and paragraph
is set up as follows:
newcommandsubsubsection{@startsection{subsubsection}{3}{z@}%
{-3.25ex@plus -1ex @minus -.2ex}%
{1.5ex @plus .2ex}%
{normalfontnormalsizebfseries}}
newcommandparagraph{@startsection{paragraph}{4}{z@}%
{3.25ex @plus1ex @minus.2ex}%
{-1em}%
{normalfontnormalsizebfseries}}
To make the paragraph
command behave more like the subsubsection
command, but with less vertical spacing above and below the sectioning header line(s), you could modify the paragraph
command to make its output behave as if it were a "subsubsubsection". The following MWE illustrates a possible setup.
documentclass{article}
makeatletter
renewcommandparagraph{@startsection{paragraph}{4}{z@}%
{-2.5ex@plus -1ex @minus -.25ex}%
{1.25ex @plus .25ex}%
{normalfontnormalsizebfseries}}
makeatother
setcounter{secnumdepth}{4} % how many sectioning levels to assign numbers to
setcounter{tocdepth}{4} % how many sectioning levels to show in ToC
begin{document}
tableofcontents
section{A}
subsection{B}
subsubsection{C1}
paragraph{D1}
paragraph{D2}
subsubsection{C2}
end{document}
Answered by Mico on November 27, 2020
I know this is an old question, but I found it with Google and I think the solutions are too complicated.
For me this is the easiest way for a subsubsubsection:
newcommand{subsubsubsection}[1]{paragraph{#1}mbox{}}
setcounter{secnumdepth}{4}
setcounter{tocdepth}{4}
After this it's possible to use
subsubsubsection{Navigator}
Answered by Daniel on November 27, 2020
The are two good answers to show how to add a new level section or modify an existing one. But both are assuming some basic knowledge of LaTeX and typography. Maybe these remarks can help to new users to decide when these or a similar approaches are the best solution.
requires many levels of sectioning
The best solution could be reconsider that premise. Is it really true? Sometimes (e.g., legal documents, huge technical reports), but often is not an imperative requirement but the insane decision of mimic this or that monstrous thesis. Defaults levels are more than enough in most documents.
I have sections, subsections and subsubsections ...
I see that the paragraph command is used ...
It seems that you are using the article
class, because you mention only this four heading levels, so the first question is
How many levels of nested subsections can the article class support? Short anwser: there are six, not four levels of sectioning.
Moreover, the book-like classes than allow one more level
(chapter
), so you can have at least seven levels (-1 to 5, not 1 to 7) without effort. Using the memoir
class you have also the option that chapters behave as sections:
documentclass[article,oneside]{memoir}
setcounter{secnumdepth}{5} % Note that part is -1 level !
setcounter{tocdepth}{5}
begin{document}
begingroup
letclearpagerelax
letnewpagerelax
tableofcontents*
part{Part}
endgroup
chapter{Chapter} Text.
section{Section} Text.
subsection{Subsection} Text.
subsubsection{Subsubsection} Text.
paragraph{Paragraph} Text.
subparagraph{Subparagraph} Text.
end{document}
Need more? For a deeper structuring of your contents you can use also the starred versions of sectioning commands (subsection*
, etc.), environment lists (enumerate
, itemize
,description
, or a custom list
) and a judicious use of blank lines (par
) to remark the content structure (often some people break paragraphs only to avoid long chunks of texts).
Still need More section headings? Well, it's up to you. Then go to other answers, or follow the last link for a ridiculously high number of sectional levels.
Answered by Fran on November 27, 2020
With KOMA-Script classes you do not need nor should use an extra package to redefine sectioning commands or define new sectioning levels. And you don't need and should not use low level code.
These classes provide command RedeclareSectionCommand
to reconfigure existing sectioning commands. For example to have a paragraph
that does not produce a title at the beginning of the paragraph (a so called catch phrase or runin title) but a displayed title, you can use:
RedeclareSectionCommand[runin=false,afterskip=1ex,afterindent=false]{paragraph}
Option runin=false
is used to make it a displayed instead of a runin title. afterskip=1ex
makes a vertical skip of 1ex after the heading. afterindent=false
prevents the following paragraph to be indented.
So the result would be something like:
If you need a paragraph number, just add
setcounter{secnumdepth}{paragraphnumdepth}
very ease with KOMA-Script. You don't need to remember the numeric value.
You can do a similar change for subparagraph
:
RedeclareSectionCommand[indent=0pt,runin=false,afterskip=1ex,afterindent=false]{subparagraph}
Here additionally indent=0pt
is used to remove the default indent of subparagraph titles.
If this is not enough, you can even define a subsubparagraph
very easily:
DeclareNewSectionCommand[style=section,level=numexpr subparagraphnumdepth+1relax,runin=false,beforeskip=1ex,afterskip=0pt,afterindent=false]{subsubparagraph}
See the KOMA-Script manual for the meaning of all the options and how to use them and all the other available options.
BTW: After defining subsubparagraph
there is also a subsubparagraphnumdepth
(and even a subsubparagraphtocdepth
) that can be used to change secnumdepth
.
Answered by Schweinebacke on November 27, 2020
This very excellent answer can also very easily be expanded to add subsubsubsection
and subsubsubsubsection
commands:
documentclass{article}
setcounter{secnumdepth}{5}
setcounter{tocdepth}{5}
makeatletter
newcommandsubsubsubsection{@startsection{paragraph}{4}{z@}{-2.5ex@plus -1ex @minus -.25ex}{1.25ex @plus .25ex}{normalfontnormalsizebfseries}}
newcommandsubsubsubsubsection{@startsection{subparagraph}{5}{z@}{-2.5ex@plus -1ex @minus -.25ex}{1.25ex @plus .25ex}{normalfontnormalsizebfseries}}
makeatother
begin{document}
tableofcontents
section{section}
subsection{subsection}
subsubsection{subsubsection}
subsubsubsection{subsubsubsection}
subsubsubsubsection{subsubsubsubsection}
end{document}
Answered by finefoot on November 27, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP