How do I change the spacing between the number and the title of a section? I would like to have the following:
1.(1cm space)Section name
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityHow do I change the spacing between the number and the title of a section? I would like to have the following:
1.(1cm space)Section name
The "1.", "(1cm space)" and "Section name" are each components of the sectional command and, the titlesec
package provides commands for manipulating this, and much more. Specifically, titlesec
provides
\titleformat{<command>}[<shape>]{<format>}{<label>}{<sep>}{<before-code>}[<after-code>]
to change the format of a sectional title. You could use the latter in the following way:
\usepackage{titlesec}% Http://ctan.org/pkg/titlesec
...
\titleformat{\section}{\bfseries\sffamily\large}{\thesection.}{\hspace{1cm}}{}%
which typesets \section
in \bfseries
(bold), \sffamily
(sans serif) and \large
, with a period .
after the section number \thesection
, followed by a 1cm
gap and then the title. This is what it looks like if you only modify the \section
format as given above:
titlesec
with a KOMA-Script class (see the koma-script tag of the question) is not longer recommended.
– Schweinebacke
Jun 5 '17 at 8:56
This adjusts the space for all section headings, and also for sub(sub)sections to 1cm:
\makeatletter
\renewcommand*{\@seccntformat}[1]{\csname the#1\endcsname\hspace{1cm}}
\makeatother
You can modify this redefinition as you desire. It works with KOMA-Script classes as well, as I notice your koma-script tag.
\renewcommand*{\@seccntformat}[1]{\hbox to 1cm{\csname the#1\endcsname}}
will do the trick.
– Christoph
Mar 22 '12 at 11:19
\renewcommand*\sectionformat{\makebox[1cm][l]{\thesection\autodot \hfil}}
.
– esdd
Jun 5 '17 at 19:42
With a KOMA-Script class you can redefine the KOMA-Script command \sectionformat
:
\renewcommand*\sectionformat{\thesection\autodot\hspace{1cm}}
Example:
\documentclass{scrbook}
\renewcommand*\sectionformat{\thesection\autodot\hspace{1cm}}
\usepackage{lipsum}
\begin{document}
\chapter{A chapter}
\lipsum[1]
\section{A section}
\lipsum[2]
\subsection{A subsection}
\lipsum[3]
\section{Another section}
\lipsum[4]
\end{document}
Note that this suggestion needs at least KOMA-Script version 3.17. Current version is 3.23.
Because of the comments to Stephans answer: If there should be a static width of eg. 1cm
for the section number including the space, then
\renewcommand*\sectionformat{\makebox[1cm][l]{\thesection\autodot\hfil}}
can be used.
\renewcommand*\sectionformat{\makebox[1cm][l]{\thesection\autodot\hfil}}
can be used.
– Schweinebacke
Jun 5 '17 at 9:00