TransWikia.com

chaptertitle not working in scrbook with scrlayer-scrpage

TeX - LaTeX Asked on May 15, 2021

I need to make the title of the current chapter appear in the header of my book.
With the standard class book I can just use titlesec package and chaptertitle:

documentclass{book}

usepackage{titlesec}
newpagestyle{main}{sethead{}{chaptername thechapter: chaptertitle}{}}
pagestyle{main}

usepackage{lipsum}

begin{document}
    chapter{Lorem Ipsum}
    section{Foo}
    lipsum[1-5]
    
    section{Bar}
    lipsum[6]
    subsection{Baz}
    lipsum[7-10]
end{document}

However, I’m using scrbook for the first time.
I understood that I can change the header content with package scrlayer-scrpage, but when I try to compile the following

documentclass{scrbook}

usepackage{scrlayer-scrpage}
lehead{}
rohead{}
chead{chaptername~thechapter: chaptertitle}

usepackage{lipsum}

begin{document}
    chapter{Lorem Ipsum}
    section{Foo}
    lipsum[1-5]
    
    section{Bar}
    lipsum[6]
    subsection{Baz}
    lipsum[7-10]
end{document}

I get two errors:

l.19 end
{document}
? h
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

? 
[2]
! Undefined control sequence.
sls@ps@scrheadings@odd@middle@head ...aptertitle 

l.19 end{document}

? h
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

?

If I just go on I get a document with headers without the chapter title:

Header only containing "Chapter 1:"

The problem should be in chaptertitle because if I remove it the documents is compiled correctly.
I’m probably missing something obvious, but I can’t understand what.

Do you have any suggestion?

One Answer

With scrbook you have to redefine chaptermarkformat:

renewcommand*chaptermarkformat{chaptername~thechapter:enspace}

Then you can use chead{leftmark}

Example:

documentclass{scrbook}
renewcommand*chaptermarkformat{chaptername~thechapter:enspace}
usepackage[automark]{scrlayer-scrpage}% <- option automark added
ohead{}
chead{leftmark}
usepackage{lipsum}

begin{document}
chapter{Lorem Ipsum}
section{Foo}
lipsum[1-5]

section{Bar}
lipsum[6]
subsection{Baz}
lipsum[7-10]
end{document}

enter image description here

Answered by esdd on May 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP