2

I am searching for a way to "neatly" achieve the following result, as I am currently using titlesec, which causes a "warning", as it is not optimised for KOMA and I am using scrreprt for my thesis. (Total LATEX noob) display So what I was trying to achieve was the format on the right: 1 | Chaptername

The chapters should not have any space above them (excuse my bad english), that's what I was using the titlespacing for. (It should be around 1,5 spacing, but I didn't know how to get that dynamic spacing, therefore shabbily "converted" it into pt) Also I'd like to stick with the style of the chapters including the vertical bar |

However my "solution" apparently is pretty bad. :D

\documentclass[12pt,a4paper,headings=standardclasses]{scrreprt}
\usepackage{showframe}
\usepackage{graphicx}
\usepackage[utf8]{inputenc} % Required for inputting international characters
\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.00cm]{geometry}
\usepackage[onehalfspacing]{setspace}
%----------------------------------------------------------------------------
%   TITLES
%----------------------------------------------------------------------------
\usepackage{titlesec}
\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage{titlesec, blindtext, color}
\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{10pt}}
\titleformat{\chapter}[hang]{\LARGE\bfseries}{\thechapter\hsp\textcolor{gray75}{|}\hsp}{0pt}{\LARGE\bfseries}
\titlespacing*{\chapter}{0pt}{-20pt}{28.8pt}
\titlespacing*{\section}{0pt}{21.6pt}{15pt}
\titlespacing*{\subsection}{0pt}{21.6pt}{14.4pt}
\titlespacing*{\subsubsection}{0pt}{21.6pt}{14.4pt}
  • Welcome to TeX.SX! You might want to have a look at \sectionlinesformat and friends, because they are the KOMA way of approaching this (the German version of the manual should be a good starter for you). But please make a minimal compilable code example (MWE) to help us help you. – TeXnician Aug 13 '18 at 12:38
8

Minimal example changing the vertical offset prior to \chapter and adding the vertical rule in between chapter number and chapter title.

Edit: As Schweinebacke mentions in the comments, since KOMA v3.26 one can use the afterindent-key and therefore instead of the code in the MWE below one should use

\RedeclareSectionCommand
  [%
    beforeskip=0pt,
    afterindent=false
  ]
  {chapter}

Note however that the difference in the two versions is only about 5.36nm and therefore not visible (and lost during rasterisation for print). The below code should works for older versions of KOMA, too, so if backwards compatibility does bother you, you should use the code below.

\documentclass[]{scrreprt}

\RedeclareSectionCommand
  [%
    beforeskip=-1sp
  ]
  {chapter}

\renewcommand\chapterformat
  {%
    \mbox
      {%
        \chapappifchapterprefix{\nobreakspace}\thechapter \autodot
        \IfUsePrefixLine{}{\enskip $|$\enskip}%
      }%
  }

\usepackage{duckuments}

\begin{document}
\duckument
\end{document}

Result with showframe:

enter image description here

  • 2
    Since KOMA-Script 3.26 you can also use beforeskip=0pt,afterindent=false instead of beforeskip=-1sp. However the difference is not visible. – Schweinebacke Apr 3 at 7:47
  • @Schweinebacke thanks for mentioning it, I didn't know about it. Well the difference is roughly 5.36nm. – Skillmon Apr 3 at 8:45
  • Yes, the difference is invisible and moreover there are still a lot of KOMA-Script versions < 3.26 in usage. So your answer is not only absolutely correct, it is also the best/only solution if backward compatibility is needed. – Schweinebacke Apr 3 at 8:49
  • 1
    @Schweinebacke edited my answer, thanks again. – Skillmon Apr 3 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.