8

So I came across some problems with the chapter layout, which has to do with the \chapter* command. This is how I have the layout set up right now, it was done by a friend, who has more experience with LaTeX and KOMA than me:

\documentclass[11pt,
chapterprefix=true 
]{scrbook} 
\usepackage[]{graphicx} 
\usepackage[scaled=.90]{helvet}
\usepackage[automark]{scrlayer-scrpage}
\usepackage{blindtext}
\usepackage{ragged2e}
\setkomafont{chapter}{\Huge\bfseries}
\addtokomafont{chapterprefix}{\raggedleft}
\renewcommand*{\raggedsection}{\raggedright} 
\renewcommand*{\chapterformat}{%
    \hrulefill\enskip\mbox{\scalebox{3}{\thechapter\autodot}}\vspace{-0.6\baselineskip}}
\newcommand{\chap}[1]{\chapter{#1}\vspace{-0.8\baselineskip}\hrule\vspace{1.5\baselineskip}}


\begin{document}
    \tableofcontents
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\blindtext

\chap{Theory}
\blindtext
\end{document}

now this results in the chapter layout I want for the "Theory" chapter, however it doesn't work for the "Introduction" chapter, because both bars are missing.

So would it be possible to have the layout like the following:

------------
Introduction
------------

text

----------1
Theory
-----------

the same way it was done in the minimal working example above, however, but also for the introduction chapter. Both chapters should be in the ToC and the "Introduction" should not be enumerated. I cannot get anything to do exactly that, maybe you guys have an idea, also any improvement to the layout in general would be greatly appreciated.

  • Welcome to TeX.SX! – moewe Sep 14 '15 at 10:42
4

Update (KOMA-Script version 3.19 is now on CTAN and in TeXLive)

There is another possibility with KOMA-Script version 3.19 or newer. With that version you can simple redefine the command \chapterlinesformat. This command is explained in the KOMA-Script documentation.

\documentclass{scrbook}[2015/09/15]
\usepackage{graphicx} 
\usepackage[scaled=.90]{helvet}
\usepackage[automark]{scrlayer-scrpage}
\usepackage{blindtext}
\setkomafont{chapter}{\Huge\bfseries}

\renewcommand*{\chapterformat}{%
  \enskip\mbox{\scalebox{3}{\thechapter\autodot}}}
\renewcommand\chapterlinesformat[3]{%
  \parbox[b]{\textwidth}{\hrulefill#2}\par%
  #3\par\bigskip
  \hrule}
\RedeclareSectionCommand[afterskip=1.5\baselineskip]{chapter}

\begin{document}
\tableofcontents
\addchap{Introduction}% \addchap instead of \chapter* and \addcontentsline
\blindtext
\chapter{Theory}
\blindtext
\blinddocument
\end{document}

Note that I have removed chapterprefix=true.

Result:

enter image description here

enter image description here

enter image description here


Here is another suggestion (for older KOMA-Script versions) also using etoolbox. The line below the chapter is inserted by \chapterheadendvskip.

\usepackage{etoolbox}
\preto{\chapterheadendvskip}{\noindent\hrulefill\par}

So you can use \chapter etc. in your code and it works also for the table of contents.

And with

\newcommand\chaptertopline{\smash{\raisebox{-3.5\baselineskip}{\rule{\textwidth}{.4pt}}}}
\makeatletter
\preto{\@@makeschapterhead}{\chaptertopline}
\preto{\@@makechapterhead}{\ifunnumbered{chapter}{\chaptertopline}{}}
\makeatother

it is also possible to use \addchap instead the combination of \chapter* and \addcontentsline.

Code:

\documentclass[
chapterprefix=true
]{scrbook}
\usepackage{graphicx}
\usepackage[scaled=.90]{helvet}
\usepackage[automark]{scrlayer-scrpage}
\usepackage{blindtext}

\setkomafont{chapter}{\Huge\bfseries}
\addtokomafont{chapterprefix}{\raggedleft}
\renewcommand*{\chapterformat}{%
    \hrulefill\enskip\mbox{\scalebox{3}{\thechapter\autodot}}\vspace{-0.6\baselineskip}}

\usepackage{etoolbox}
\newcommand\chaptertopline{\smash{\raisebox{-3.5\baselineskip}{\rule{\textwidth}{.4pt}}}}
\makeatletter
\preto{\@@makeschapterhead}{\chaptertopline}
\preto{\@@makechapterhead}{\ifunnumbered{chapter}{\chaptertopline}{}}
\makeatother
\preto{\chapterheadendvskip}{\noindent\hrulefill\par}

\begin{document}
\tableofcontents
\addchap{Introduction}
\blindtext

\chapter{Theory}
\blindtext
\end{document}

Result:

enter image description here

enter image description here

enter image description here

  • Can this be used here, too: tex.stackexchange.com/q/266730 ? – clemens Sep 14 '15 at 14:54
  • Can you elaborate on the example above? How did you manage to add the chapter number only for the "Theory" chapter when using the \chapterheadendvskip command? – Ringli Sep 14 '15 at 15:33
  • @Ringli Sorry, I forgot the MWE. I have now added it. – esdd Sep 14 '15 at 20:17
1

Try this. I used the etoolbox package to patch \@@makeschapterhead to get the line above the heading. The \chapst command starts an unnumbered chapter and puts in the line below. Finally, \mychap works like \chapter, so you can use it without a star for a numbered section or with a star if you don't want a number.

\documentclass[11pt,
chapterprefix=true
]{scrbook}
\usepackage[]{graphicx}
\usepackage[scaled=.90]{helvet}
\usepackage[automark]{scrlayer-scrpage}
\usepackage{blindtext}
\usepackage{ragged2e}
\usepackage{etoolbox}
\setkomafont{chapter}{\Huge\bfseries}
\addtokomafont{chapterprefix}{\raggedleft}
\renewcommand*{\raggedsection}{\raggedright}
\renewcommand*{\chapterformat}{%                                                                                                                            
    \hrulefill\enskip\mbox{\scalebox{3}{\thechapter\autodot}}\vspace{-0.6\baselineskip}}
\newcommand{\chap}[1]{\chapter{#1}\vspace{-0.8\baselineskip}\hrule\vspace{1.5\baselineskip}}
\newcommand\chapst[1]{\chapter*{#1}\vspace{-0.8\baselineskip}\hrule\vspace{1.5\baselineskip}}


\makeatletter
\pretocmd{\@@makeschapterhead}{\noindent\hrulefill\par\vspace{-2\baselineskip}}{}{}

\newcommand\mychap{\@ifstar\chapst\chap}

\makeatother

\begin{document}
    \tableofcontents
\mychap*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\blindtext

\mychap{Theory}
\blindtext
\end{document}

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.