抑制 mainmatter 章節第一頁的頁碼,但*不是* frontmatter 的頁碼

抑制 mainmatter 章節第一頁的頁碼,但*不是* frontmatter 的頁碼

我正在使用書籍課程。我想在我的 mainmatter 的每一章的第一頁中隱藏頁面樣式(頁碼、頁首、頁尾),但是不是in \frontmatter- 我想在頁腳(右上角)中有羅馬數字。

我可以使用以下命令在整個文件範圍內抑制每個章節的第一頁中的頁面樣式:

\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                \thispagestyle{empty}% original style: plain
                \global\@topnum\z@
                \@afterindentfalse
                \secdef\@chapter\@schapter}
\makeatother

但這\pagestyle{empty}也在 frontmatter 的每個「章節」的第一頁中強加了一個 ,因此目錄頁沒有編號。我希望對目錄頁進行編號,但我不知道該怎麼做。

微量元素:

\documentclass[a4paper,11pt,titlepage,oneside,openany]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{kantlipsum}
% empty style for the first page of every chapter
\makeatletter
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                \thispagestyle{empty}% original style: plain
                \global\@topnum\z@
                \@afterindentfalse
                \secdef\@chapter\@schapter}
\makeatother

\usepackage{makeidx}

\usepackage[titles]{tocloft}

\usepackage{fancyhdr}
\fancyhead{} % clear default layout
\fancyfoot{} % clear default layout
\fancypagestyle{mainmatter}{%
\fancyhead[L]{\sffamily \small \color{darkgray}\MakeUppercase{\bfseries        \leftmark}}  
\fancyhead[R]{\nouppercase \scshape \small \thepage}
}

\fancypagestyle{frontmatter}{%
\fancyhead[L]{}
\fancyhead[R]{}
\fancyfoot[R]{\thepage}
}

\begin{document}
\frontmatter
\pagestyle{frontmatter}% frontmatter page style
\clearpage
\tableofcontents
\clearpage % with tocloft we need this
\listoffigures
\clearpage % with tocloft we need this
\listoftables
\clearpage

\mainmatter
\pagestyle{mainmatter}

\chapter{A}
\kant
\chapter{B}
\kant
\chapter{C}
\kant
\end{document}

答案1

memoir\if@mainmatter提供可用於判斷您是否位於\mainmatter文件部分的條件:

\documentclass[a4paper,11pt,titlepage,oneside,openany]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{kantlipsum}
% empty style for the first page of every chapter, except in \frontmatter
\makeatletter
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                \if@mainmatter
                  \thispagestyle{empty}% plain page style in mainmatter
                \else
                  \thispagestyle{plain}% empty page style outside of mainmatter
                \fi%
                \global\@topnum\z@
                \@afterindentfalse
                \secdef\@chapter\@schapter}
\makeatother

\usepackage{makeidx}

\usepackage[titles]{tocloft}

\usepackage{fancyhdr}
\fancyhead{} % clear default layout
\fancyfoot{} % clear default layout
\fancypagestyle{mainmatter}{%
\fancyhead[L]{\sffamily \small \color{darkgray}\MakeUppercase{\bfseries        \leftmark}}  
\fancyhead[R]{\nouppercase \scshape \small \thepage}
}

\fancypagestyle{frontmatter}{%
\fancyhead[L]{}
\fancyhead[R]{}
\fancyfoot[R]{\thepage}
}

\begin{document}
\frontmatter
\pagestyle{frontmatter}% frontmatter page style
\clearpage
\tableofcontents
\clearpage % with tocloft we need this
\listoffigures
\clearpage % with tocloft we need this
\listoftables
\clearpage

\mainmatter
\pagestyle{mainmatter}

\chapter{A}
\kant
\chapter{B}
\kant
\chapter{C}
\kant
\end{document}

雖然我分別在 mainmatter 和 frontmatter 中使用了emptyplain作為章節頁面樣式,但您可以將其更新為您想要的任何內容,甚至創建您自己的新樣式。

另請注意,它memoir提供了創建頁眉/頁腳的功能,因此您不需要fancyhdr為了這。

答案2

titlesec軟體包提供了該\assignpagestyle{\chapter}{<style>}命令,可以像使用該命令一樣使用\pagestyle,但僅更改每章的第一頁。這與您對 所做的相同\thispagestyle{},但沒有明確更新\chapter

相關內容