LaTeX forum ⇒ Text Formatting ⇒ Space between section number and section title

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

Space between section number and section title

Hello!

I'm currently trying to achieve the following text layout:

design.png (25.12 KiB) Viewed 1525 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:

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

\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

Tags:

Stefan Kottwitz
Posts: 9434
Joined: Mon Mar 10, 2008 9:44 pm
Hi Murd,

welcome to the forum!

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

\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 (47.15 KiB) Viewed 1523 times

By the way, as I see you are writing in German, you are also welcome in our German partner forum TeXwelt.

Stefan

Murd
Posts: 5
Joined: Wed Aug 29, 2018 3:44 pm
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
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?

Stefan Kottwitz
Posts: 9434
Joined: Mon Mar 10, 2008 9:44 pm
We can fix it by adding [b] for bottom alignment of the parbox:

\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