\pagestyle{plain} 章節之間標題頁後面沒有頁碼?

\pagestyle{plain} 章節之間標題頁後面沒有頁碼?

我發現了很多關於刪除章節之間空白頁上的頁眉/頁腳的帖子,它們工作得很好,但有一個很大的例外......我需要\pagestyle{plain}在文檔中的章節開始之前的所有空白頁上都有一個(即單居中的pg#)除了我需要一個\pagestyle{empty}頁面就在之後\titlepage。我見過和嘗試過的所有方法要么讓我留下整個文件或\pagestyle{plain}所有文件的完全空白頁面。

我正在使用book文檔類[twosided,openright]fancyhdr,並包含重新定義的程式碼,\cleardoublepage如下所示:

\makeatletter
\def
\cleardoublepage{%
\clearpage
  \ifodd\c@page
  \else
    \hbox{}
    \thispagestyle{plain}
    \newpage      
  \fi
  }%
\makeatother

……正如各種帖子中所推薦的那樣。不幸的是,這讓我在titlepage頁碼後面留下了空白頁(這讓客戶抓狂)。該程式碼似乎覆蓋了將該頁面訪問到的任何內聯嘗試{empty}

是否有某種形式的\if@titlepage條件與\if@mainmatter我可以用來清除該部分並保留其餘部分(\frontmatter, \mainmatter, \appendix, \backmatter)作為\pagestyle{plain}中間的空白頁?有什麼方法可以將其捕獲為條件嗎?

一個(非常)粗略的 MWE 近似值:

\documentclass[12pt,letterpaper,final,openright]{book}

\usepackage{fancyhdr}
\usepackage{natbib}

\pagestyle{fancy}
  \setlength{\headheight}{15.2pt}
  \renewcommand{\headrulewidth}{0.4pt}
  \renewcommand{\footrulewidth}{0.2pt}

  \makeatletter
    \renewcommand{\chaptermark}[1]{%
      \if@mainmatter
        \markboth{\MakeUppercase{\chaptername\ \thechapter.\ #1}}{}
      \else
        \markboth{\MakeUppercase{#1}}{\MakeUppercase{#1}}
      \fi
      }%
  \makeatother  

  \fancyhf{} 
  \fancyhead[LE,RO]{\small \thepage}
  \fancyhead[LO]{\small \leftmark}
  \fancyhead[RE]{\small \rightmark}

% Redefine \pagestyle{plain}
\fancypagestyle{plain}{%
  \fancyhf{} % clear all header and footer fields
  \fancyfoot[C]{\small \thepage} % except the center
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
  }%

% Code for creating plain on empty pages before new chapter
\makeatletter
\def
  \cleardoublepage{%
    \clearpage
      \ifodd\c@page
      \else
        \hbox{}
        \thispagestyle{plain}
        \newpage      
      \fi
    }%
\makeatother

\begin{document}
% TITLE PAGE
\pagestyle{empty}  %Clear hdr/ftr 
\titlepage
  \input{./Chapter_txt/titlepageV1} %Custom title page text/layout

\frontmatter
\pagestyle{fancy} % Resume hdr/ftr
%MANAGEMENT SUMMARY 
\include{Preface} %Intro/Preface chapter

%ToC and Lists  
\tableofcontents
\listoftables   
\listoffigures

\mainmatter
\part{PartI}
  \include{Chapter1}
  \include{Chapter2}
\part{PartII}
  \include{Chapter3}
  \include{Chapter4}

\appendix
  \include{app}

\backmatter  
    \bibliographystyle{humannat}
    \bibliography{mybib}\footnotesize
    \addcontentsline{toc}{chapter}{Bibliography}

\end{document}

整本書是一部多卷本的作品,每個部分都由\include{file}…繪製而成,這不是做大部分 MWE 的好方法(不知道如何做有\input或 的內容\include)。

答案1

這是一個解決方案編輯:更多解釋

plain頁面樣式很奇特,章節之間的頁面透過重新定義設定(最後一個指令由and\cleardoublepage使用)\part\chapter

plain部分頁面之後的頁面透過重新定義設定為\@endpart

empty標題頁之後的頁面透過此 pagestyle{empty}設定為緊鄰titlepage環境之後

\documentclass{book}
\usepackage{lipsum}
\usepackage{fancyhdr}
\fancyhf{}  
\fancyhead[R]{\leftmark} 
\fancyfoot[R]{test} 
\fancyfoot[C]{\thepage}
\pagestyle{fancy}
\let\mtcleardoublepage\cleardoublepage
\renewcommand{\cleardoublepage}{\clearpage{\pagestyle{plain}\mtcleardoublepage}}
\makeatletter
\def\@endpart{\vfil\newpage
              \if@twoside
               \if@openright
                \null
                \thispagestyle{plain}%
                \newpage
               \fi
              \fi
              \if@tempswa
                \twocolumn
              \fi}
\makeatother
\title{Test}
\author{Me}
\begin{document}
\begin{titlepage}
\maketitle
\end{titlepage}
\thispagestyle{empty}
\lipsum[1-20]
\part{Deux}
\chapter{trois}
\lipsum[1-50]
\end{document}

編輯:這個特定的程式碼

\documentclass[12pt]{book}

\usepackage{fancyhdr}
\usepackage{natbib}

\pagestyle{fancy}
  \setlength{\headheight}{15.2pt}
  \renewcommand{\headrulewidth}{0.4pt}
  \renewcommand{\footrulewidth}{0.2pt}

  \makeatletter
    \renewcommand{\chaptermark}[1]{%
      \if@mainmatter
        \markboth{\MakeUppercase{\chaptername\ \thechapter.\ #1}}{}
      \else
        \markboth{\MakeUppercase{#1}}{\MakeUppercase{#1}}
      \fi
      }%
  \makeatother  

  \fancyhf{} 
  \fancyhead[LE,RO]{\small \thepage}
  \fancyhead[LO]{\small \leftmark}
  \fancyhead[RE]{\small \rightmark}

% Redefine \pagestyle{plain}
\fancypagestyle{plain}{%
  \fancyhf{} % clear all header and footer fields
  \fancyfoot[C]{\small \thepage} % except the center
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
  }%

\let\mtcleardoublepage\cleardoublepage
\renewcommand{\cleardoublepage}{\clearpage{\pagestyle{plain}\mtcleardoublepage}}
\makeatletter
\def\@endpart{\vfil\newpage
              \if@twoside
               \if@openright
                \null
                \thispagestyle{plain}%
                \newpage
               \fi
              \fi
              \if@tempswa
                \twocolumn
              \fi}
\makeatother

\begin{document}

\begin{titlepage}
test
\end{titlepage}
\thispagestyle{empty}
\frontmatter

\include{Preface} %Intro/Preface chapter

%ToC and Lists  
\tableofcontents
\listoftables   
\listoffigures

\mainmatter
\part{PartI}
  \include{Chapter1}
  \include{Chapter2}
\part{PartII}
  \include{Chapter3}
  \include{Chapter4}

\appendix
  \include{app}

\backmatter 
\footnotesize 
    \bibliographystyle{humannat}
    \bibliography{mybib}
    \addcontentsline{toc}{chapter}{Bibliography}

\end{document}

答案2

您可能需要重新定義您的titlepage環境。我的就是這樣,扉頁之後的第一頁是空的,下面的編號是正確的。

\newenvironment{titlepage}
{%
  \if@openright
    \cleardoublepage
  \else
    \clearpage
  \fi%
  \newpage
  \thispagestyle{empty}%
  \setcounter{page}\@ne
}%
{\newpage
  \thispagestyle{empty}
}%%

此外,如果使用\maketitle命令,則應\clearpage在命令定義末尾添加:

\if@titlepage
\newcommand\maketitle{%
  \begin{titlepage}
...
  \end{titlepage}%
  \clearpage%
  \setcounter{footnote}{0}%
...
}%
\fi

我希望它有幫助。

答案3

就可以載入套件了scrextend與選項cleardoublepage=plain。要在標題頁之後立即獲得一個空白頁面,請在環境\cleardoubleoddemptypage之後使用titlepage或作為該環境中的最後一個命令。

\documentclass{book}
\usepackage[cleardoublepage=plain]{scrextend}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{blindtext}% dummy text
\begin{document}
\begin{titlepage}
\Huge My Titlepage
\end{titlepage}
\cleardoubleoddemptypage
\frontmatter
\tableofcontents
\mainmatter
\blinddocument
\Blindtext
\blinddocument
\end{document}

另一種可能性是額外使用etoolbox:

\documentclass{book}
%
\usepackage[cleardoublepage=plain]{scrextend}
\usepackage{etoolbox}
\AfterEndEnvironment{titlepage}{\cleardoubleoddemptypage}
%
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{blindtext}% dummy text
\begin{document}
\begin{titlepage}
\Huge My Titlepage
\end{titlepage}
\frontmatter
\tableofcontents
\mainmatter
\blinddocument
\Blindtext
\blinddocument
\end{document}

相關內容