我需要让当前章节的标题出现在我的书的标题中。使用标准类,book
我只需使用titlesec
包和\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}
scrbook
但是,这是我第一次使用。我知道我可以使用 package 更改标头内容scrlayer-scrpage
,但是当我尝试编译以下内容时
\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}
我收到两个错误:
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., `I\hbox'). 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., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
?
如果我继续下去,我会得到一个带有标题但没有章节标题的文档:
问题应该出在这里,\chaptertitle
因为如果我删除它,文档就会被正确编译。我可能忽略了一些显而易见的东西,但我不明白什么。
你有什么建议吗?
答案1
你scrbook
必须重新定义\chaptermarkformat
:
\renewcommand*\chaptermarkformat{\chaptername~\thechapter:\enspace}
然后你可以使用\chead{\leftmark}
例子:
\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}