Text FormattingSpace between section number and section title

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Murd
Posts: 5
Joined: Wed Aug 29, 2018 3:44 pm

Space between section number and section title

Post by Murd »

Hello!

I'm currently trying to achieve the following text layout:
design.png
design.png (25.12 KiB) Viewed 12179 times
It consists of the chapter, section, subsection (...) numbering being indented to the left, while the chapter, section, subsection (...) title being on one level to the text.

I already searched for a solution, but could not get it quite right. Here is what I already tried:

Code: Select all

\titleformat{\section}{\normalfont\Large\bfseries}{\thesection}{4pt}{}

Code: Select all

\renewcommand{\@seccntformat}[1]{\csname the#1\endcsname\ }
Both approaches just change the spacing between the number and the title, but not put them all on the same level.

Can anyone help me with that?

Thanks!
Murd

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10397
Joined: Mon Mar 10, 2008 9:44 pm

Space between section number and section title

Post by Stefan Kottwitz »

Hi Murd,

welcome to the forum!

With some settings by Gonzalo Medina (user gmedina here on latex.org):

Code: Select all

\documentclass{scrartcl}
\usepackage{titlesec}
\usepackage[ngerman]{babel}
\usepackage{blindtext}

% adjust the indentation value as desired
\newlength\titleindent
\setlength\titleindent{2cm}

\titleformat{\section}
  {\sffamily\Large\bfseries}{\llap{\parbox{\titleindent}{\bfseries\thesection\hfill}}}{0em}{}
\titleformat{\subsection}
  {\sffamily\large}{\llap{\parbox{\titleindent}{\bfseries\thesubsection\hfill}}}{0em}{\bfseries}
\titleformat{\subsubsection}
  {\sffamily\normalsize}{\llap{\parbox{\titleindent}{\bfseries\thesubsubsection}}}{0em}{\bfseries}
\begin{document}

\section{Testdokument}

See the following sample.

\subsection{Projektphase1}

\blindtext

\subsubsection{Budgetplanung}

\blindtext
\end{document}
\llap puts the number in the box with the width of the indentation, left aligned, but zero box width, so it's pushed to the left.
indent.png
indent.png (47.15 KiB) Viewed 12177 times
By the way, as I see you are writing in German, you are also welcome in our German partner forum TeXwelt.

Stefan
LaTeX.org admin
Murd
Posts: 5
Joined: Wed Aug 29, 2018 3:44 pm

Space between section number and section title

Post by Murd »

Thank you very much, Stefan! It works great!

Sure, I will check the german forum out as well.
Murd
Posts: 5
Joined: Wed Aug 29, 2018 3:44 pm

Space between section number and section title

Post by Murd »

I just noticed, that the title number seems to be a little bit lower than the title text. Is there a way to offset the number up a bit?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10397
Joined: Mon Mar 10, 2008 9:44 pm

Space between section number and section title

Post by Stefan Kottwitz »

We can fix it by adding for bottom alignment of the parbox:

Code: Select all

\titleformat{\section}
  {\sffamily\Large\bfseries}{\llap{\parbox[b]{\titleindent}{\bfseries\thesection\hfill}}}{0em}{}
\titleformat{\subsection}
  {\sffamily\large}{\llap{\parbox[b]{\titleindent}{\bfseries\thesubsection\hfill}}}{0em}{\bfseries}
\titleformat{\subsubsection}
  {\sffamily\normalsize}{\llap{\parbox[b]{\titleindent}{\bfseries\thesubsubsection}}}{0em}{\bfseries}
Stefan
LaTeX.org admin
Post Reply