LaTeX forum ⇒ Text FormattingSpace 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

Postby Murd » Wed Aug 29, 2018 3:52 pm

Hello!

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

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

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

  1. \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:

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

Postby Stefan Kottwitz » Wed Aug 29, 2018 4:36 pm

Hi Murd,

welcome to the forum!

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

  1. \documentclass{scrartcl}
  2. \usepackage{titlesec}
  3. \usepackage[ngerman]{babel}
  4. \usepackage{blindtext}
  5.  
  6. % adjust the indentation value as desired
  7. \newlength\titleindent
  8. \setlength\titleindent{2cm}
  9.  
  10. \titleformat{\section}
  11. {\sffamily\Large\bfseries}{\llap{\parbox{\titleindent}{\bfseries\thesection\hfill}}}{0em}{}
  12. \titleformat{\subsection}
  13. {\sffamily\large}{\llap{\parbox{\titleindent}{\bfseries\thesubsection\hfill}}}{0em}{\bfseries}
  14. \titleformat{\subsubsection}
  15. {\sffamily\normalsize}{\llap{\parbox{\titleindent}{\bfseries\thesubsubsection}}}{0em}{\bfseries}
  16. \begin{document}
  17.  
  18. \section{Testdokument}
  19.  
  20. See the following sample.
  21.  
  22. \subsection{Projektphase1}
  23.  
  24. \blindtext
  25.  
  26. \subsubsection{Budgetplanung}
  27.  
  28. \blindtext
  29. \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 1489 times


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

Stefan
Site admin

Murd
Posts: 5
Joined: Wed Aug 29, 2018 3:44 pm

Postby Murd » Wed Aug 29, 2018 7:17 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

Postby Murd » Wed Aug 29, 2018 8:01 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?

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

Postby Stefan Kottwitz » Wed Aug 29, 2018 9:54 pm

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

  1. \titleformat{\section}
  2. {\sffamily\Large\bfseries}{\llap{\parbox[b]{\titleindent}{\bfseries\thesection\hfill}}}{0em}{}
  3. \titleformat{\subsection}
  4. {\sffamily\large}{\llap{\parbox[b]{\titleindent}{\bfseries\thesubsection\hfill}}}{0em}{\bfseries}
  5. \titleformat{\subsubsection}
  6. {\sffamily\normalsize}{\llap{\parbox[b]{\titleindent}{\bfseries\thesubsubsection}}}{0em}{\bfseries}


Stefan
Site admin


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 4 guests