is there any chance to customize the spacing between the (sub)section number and its title in every appearance in the document? That is, in any header or footer as well as in the table of contents and the main part of the document?
In this particular case, I have a scrartcl document, but a class-independent solution would be really helpful.
- 231,401
-
Some related questions: vertical distance, table of contents. – user202729 Nov 17 '22 at 18:09
1 Answers
Those section numbers are used in several places using different formatting commands, such as in the TOC, in headers and in the body text. That's why the answer consists of several parts.
For a class independent solution you could use packages:
titlesecis very useful for customizing headings in the text.titletocor the powerfultocloftcould help formatting the numbers in the TOC.scrpage2orfancyhdrcould be used to modify the header and the footer.
In that case have a look at the respective package documentation.
With LaTeX's base classes you could redefine internal macros. KOMA-Script classes provide additional formatting macros, which are described in the manual.
Let's have a look at the base LaTeX side. LaTeX formats section numbers by \@seccntformat which is defined this way:
\def\@seccntformat#1{\csname the#1\endcsname\quad}
You could redefine it to replace the \quad by your customized distance:
\makeatletter
\renewcommand*{\@seccntformat}[1]{\csname the#1\endcsname\hspace{1em}}
\makeatother
Within the TOC, LaTeX uses \numberline for the section numbers, defined by
\def\numberline#1{\hb@xt@\@tempdima{#1\hfil}}
Also this could be redefined:
\makeatletter
\renewcommand*{\numberline}[1]{\hb@xt@1em{#1\hfil}}
\makeatother
Now we come to the headings. Since you're using a KOMA-Script class, let's redefine a KOMA formatting command for the number:
Originally it uses \enskip:
\newcommand*\sectionmarkformat{\thesection\autodot\enskip}
\enskip is skips half of 1 em, as defined in the LaTeX kernel:
`\def\enskip{\hskip.5em\relax}`.
Redefinition:
\renewcommand*{\sectionmarkformat}{\thesection\autodot\hspace{1em}\relax}
Do similarly for \subsectionmarkformat.
With base classes you could redefine \sectionmark etc. which uses \quad for the spacing.
- 231,401
-
1AFAIK it is not recommended to use
titlesecortocloftwith a KOMA-Script class. AFAIK with current KOMA-Script you should also redefine\sectionformat. Instead ofscrpage2you should usescrlayer-scrpage(or onlyscrlayer). – Schweinebacke Mar 07 '17 at 11:36