如何在页面标题中显示开始章节的部分?
在后续页面上会显示章节和部分,但不会在章节开始的页面上显示。
如果没有充分理由不显示该部分,我希望显示它。
另外,第 3 页不显示章节。显示的不是章节和部分,而是“列表列表”。
\documentclass[
final,
12pt,
a4paper,
oneside
]{book}
\usepackage[titles]{tocloft}% to alighn the TOC numbers on the right
\usepackage{setspace}
\usepackage{epstopdf}
\usepackage{textcomp}
\usepackage{listings}
\usepackage{etoolbox}
%%# IN NEW BEGIN
\usepackage{lipsum}
\usepackage[headheight=30pt,
a4paper,
left=42mm,
right=29mm,
top=32mm,
bottom=38mm
]{geometry} % or %\setlength{\headheight}{30pt}
%% IN NEW END
\usepackage{fancyhdr}
%\pagestyle{fancy}
%\pagestyle{fancyplain}
%\fancyhead{}
%\fancyfoot{}
\fancyhead[L]{}
\fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
\fancyfoot[L]{\rule{2cm}{1cm}}
\fancyfoot[R]{\thepage}
\fancyfoot[C]{}
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
\fancyfoot[L]{\rule{2cm}{1cm}}
\fancyfoot[R]{\thepage}
\fancyfoot[C]{}
\renewcommand{\headrule}{{%
\hrule height 1.9pt width\headwidth
\vspace{1.6pt}%
\hrule height 0.9pt width\headwidth
}}}
\renewcommand{\headrule}{{%
\hrule height 1.9pt width\headwidth
\vspace{1.6pt}%
\hrule height 0.9pt width\headwidth
}}
\makeatletter
\patchcmd{\tableofcontents}
{\@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}
{\@mkboth{\mbox{}}{\MakeUppercase\contentsname}}
{}{}
\makeatother
\begin{document}
\renewcommand{\cftchapaftersnum}{.}
%%# IN NEW BEGIN
\pagestyle{fancy}
%%# IN NEW END
\frontmatter
%% OUT NEW BEGIN
%\pagenumbering{Roman}
%% OUT NEW BEGIN
%% OUT NEW BEGIN
%\fancyfoot[RO, LE] {\small\thepage}
%\thispagestyle{empty}
%\fancyfoot[R] {\thepage}
%% OUT NEW END
\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}
\renewcommand\lstlistingname{Code listing}
\renewcommand\lstlistlistingname{List of Listings}
\rhead{\small{List of Listings}}
\addcontentsline{toc}{chapter}{List of Listings}
\lstlistoflistings
\mainmatter
%% IN NEW BEGIN
\renewcommand{\sectionmark}[1]{\markright{\thesection~#1}}
%% IN NEW END
\pagenumbering{arabic}
\onehalfspacing
%% OUT NEW BEGIN
%\fancyhead{}
%\pagestyle{plain}
%\lhead{}
%\rhead{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
%\fancyfoot[R] {\thepage}
%% OUT NEW END
\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}
\chapter{Some Chapter}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\section{Some section}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\section{Some section}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\end{document}
答案1
首先,删除该线\rhead{\small{List of Listings}}
。
标记命令设置三个变量:(\topmark
上一页的最后一个标记)、firstmark
(当前页的第一个标记)和\botmark
(当前页的最后一个标记)。\rightmark
使用\firstmark
设置的\markright
或的第二个参数\markboth
。在章节页上,第一次调用\markboth
是由完成的\chapter
,通常使用一个空的第二个参数来重置标题条目。
如果可以使用章节页面上的最后一节,你可以定义一个命令\rightbotmark
来\botmark
代替\firstmark
\makeatletter
\providecommand*{\rightbotmark}{\expandafter\@rightmark\botmark\@empty\@empty}
\makeatother
进而
\fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightbotmark}
在 pagestyleplain
并且也许还在 pagestyle fancy
。
代码:
\documentclass[
final,
12pt,
a4paper,
oneside
]{book}
\usepackage[titles]{tocloft}% to alighn the TOC numbers on the right
\usepackage{setspace}
\usepackage{epstopdf}
\usepackage{textcomp}
\usepackage{listings}
\usepackage{etoolbox}
%%# IN NEW BEGIN
\usepackage{lipsum}
\usepackage[headheight=30pt,
a4paper,
left=42mm,
right=29mm,
top=32mm,
bottom=38mm
]{geometry} % or %\setlength{\headheight}{30pt}
%% IN NEW END
\makeatletter
\providecommand*{\rightbotmark}{\expandafter\@rightmark\botmark\@empty\@empty}
\makeatother
\usepackage{fancyhdr}
%\pagestyle{fancy}
%\pagestyle{fancyplain}
%\fancyhead{}
%\fancyfoot{}
\fancyhead[L]{}
\fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
\fancyfoot[L]{\rule{2cm}{1cm}}
\fancyfoot[R]{\thepage}
\fancyfoot[C]{}
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightbotmark}
\fancyfoot[L]{\rule{2cm}{1cm}}
\fancyfoot[R]{\thepage}
\fancyfoot[C]{}
\renewcommand{\headrule}{{%
\hrule height 1.9pt width\headwidth
\vspace{1.6pt}%
\hrule height 0.9pt width\headwidth
}}}
\renewcommand{\headrule}{{%
\hrule height 1.9pt width\headwidth
\vspace{1.6pt}%
\hrule height 0.9pt width\headwidth
}}
\makeatletter
\patchcmd{\tableofcontents}
{\@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}
{\@mkboth{\mbox{}}{\MakeUppercase\contentsname}}
{}{}
\makeatother
\usepackage{lipsum}% only for dummy text
\begin{document}
\renewcommand{\cftchapaftersnum}{.}
%%# IN NEW BEGIN
\pagestyle{fancy}
%%# IN NEW END
\frontmatter
%% OUT NEW BEGIN
%\pagenumbering{Roman}
%% OUT NEW BEGIN
%% OUT NEW BEGIN
%\fancyfoot[RO, LE] {\small\thepage}
%\thispagestyle{empty}
%\fancyfoot[R] {\thepage}
%% OUT NEW END
\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}
\renewcommand\lstlistingname{Code listing}
\renewcommand\lstlistlistingname{List of Listings}
%\rhead{\small{List of Listings}}% <- remove this
\addcontentsline{toc}{chapter}{List of Listings}
\lstlistoflistings
\mainmatter
%% IN NEW BEGIN
\renewcommand{\sectionmark}[1]{\markright{\thesection~#1}}
%% IN NEW END
\pagenumbering{arabic}
\onehalfspacing
%% OUT NEW BEGIN
%\fancyhead{}
%\pagestyle{plain}
%\lhead{}
%\rhead{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
%\fancyfoot[R] {\thepage}
%% OUT NEW END
\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}
\chapter{Some Chapter}
\lipsum[1]
\section{Some section}
\lipsum[1-5]
\section{Some section}
\lipsum[1-2]
\end{document}