隐藏章节首页的页脚

隐藏章节首页的页脚

我怎样才能从下面给出的代码中隐藏章节第一页的页脚?

\documentclass{book}
\usepackage{lmodern}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{background}
\usetikzlibrary{calc}
\usepackage{lipsum}

\pagestyle{plain}

% auxiliary counter
\newcounter{chapshift}
\addtocounter{chapshift}{-1}

% the list of colors to be used (add more if needed)
\newcommand\BoxColor{%
  \ifcase\thechapshift blue!30\or red!30\or olive!30\or magenta!30\else yellow!30\fi}


% redefinition of \chaptermark to contain only the title
\renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}}

%======================================================================================
%   PAGE HEADERS
%======================================================================================

\usepackage{etoolbox,fancyhdr} % Required for header and footer configuration

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\sffamily\normalsize\bfseries \ #1}{}} % Chapter text font settings
\renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize\thesection\hspace{5pt}#1}{}} % Section text font settings
\fancyhf{} \fancyhead[LE,RO]{\sffamily\normalsize\thepage} % Font setting for the page number in the header
\fancyhead[LO]{\rightmark%
\begin{tikzpicture}[overlay,remember picture]
  \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
    text height=4cm,align=center,anchor=north east]
  at ($ (current page.north east) + (-0cm,-2*\thechapshift cm) $)
  {\rotatebox{90}{\parbox{4cm}{%
    \centering\textcolor{black}{\scshape\leftmark}}}};
  \end{tikzpicture}} % Print the nearest section name on the left side of odd pages
\fancyhead[RE]{\leftmark%
  \begin{tikzpicture}[overlay,remember picture]
  \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
    text height=4cm,align=center,anchor=north west]
  at ($ (current page.north west) + (-0cm,-2*\thechapshift cm) $)
  {\rotatebox{90}{\parbox{4cm}{%
    \centering\textcolor{black}{\scshape\leftmark}}}};
  \end{tikzpicture}} % Print the current chapter name on the right side of even pages
\renewcommand{\headrulewidth}{.5pt} % Width of the rule under the header
\addtolength{\headheight}{2.5pt} % Increase the spacing around the header slightly
\newcommand{\footrulecolor}[1]{\patchcmd{\footrule}{\hrule}{\color{#1}\hrule}{}{}}
\renewcommand{\footrulewidth}{.5pt}
\cfoot[\fancyplain{}{}] {\fancyplain{}{\footnotesize\bfseries{Center Foot}}} \lfoot[\fancyplain{}{}]
{\fancyplain{}{\footnotesize\bfseries\itshape{Left Foot}}}
\rfoot[\fancyplain{}{}]
{\fancyplain{}{\footnotesize\bfseries\itshape{Right Foot}}}
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}} % Style for when a plain pagestyle is specified


% Removes the header from odd empty pages at the end of chapters
\makeatletter
\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}
\patchcmd{\@makechapterhead}
  {\vskip 40\p@}
  {\vskip 40\p@\stepcounter{chapshift}}{}{}
\makeatother

\begin{document}
\part{Part One}
\mainmatter
\chapter[Intro]{Introduction}
\lipsum[1-7]
\section{This is how we do it}
\lipsum[1-7]

\chapter{Results}
\lipsum[1-7]

\chapter{Some Sample Code}
\lipsum[1-7]

\part{Part Two}
\appendix
\renewcommand\chaptermark[1]{\markboth{\sffamily\normalsize\bfseries \appendixname~\thechapter}{}}
\chapter{This is Appendix A}
\lipsum[1-7]

\chapter{This is Appendix B}
\lipsum[1-7]


\end{document} 

答案1

下面我更新了\chapter(感谢xparse)仅更改章节第一页的页面样式。新的页面样式(称为chapter)可以使用常规fancyhdr样式。例如,以下内容将删除它的所有痕迹 - 页眉和页脚,以及规则:

\fancypagestyle{chapter}{%
  \fancyhf{}% Clear header/footer
  \renewcommand{\headrulewidth}{0pt}% No header rule
  \renewcommand{\footrulewidth}{0pt}% No footer rule
}

\usepackage{xparse}
\let\oldchapter\chapter
\RenewDocumentCommand{\chapter}{s o m}{%
  \cleardoublepage
  \IfBooleanTF{#1}
    {\oldchapter*{#3}}% \chapter*
    {\IfNoValueTF{#2}
       {\oldchapter{#3}}% \chapter{..}
       {\oldchapter[#2]{#3}}% \chapter[.]{..}
    }
  \thispagestyle{chapter}% Special \chapter-only page style
}

chapter这是使用上述页面样式和重新定义命令的完整最小示例\chapter

在此处输入图片描述

\documentclass{book}
\usepackage{lmodern}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{background}
\usetikzlibrary{calc}
\usepackage{lipsum}

\pagestyle{plain}

% auxiliary counter
\newcounter{chapshift}
\addtocounter{chapshift}{-1}

% the list of colors to be used (add more if needed)
\newcommand\BoxColor{%
  \ifcase\thechapshift blue!30\or red!30\or olive!30\or magenta!30\else yellow!30\fi}


% redefinition of \chaptermark to contain only the title
\renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}}

%======================================================================================
%   PAGE HEADERS
%======================================================================================

\usepackage{etoolbox,fancyhdr} % Required for header and footer configuration

\fancypagestyle{chapter}{%
  \fancyhf{}% Clear header/footer
  \renewcommand{\headrulewidth}{0pt}% No header rule
  \renewcommand{\footrulewidth}{0pt}% No footer rule
}

\usepackage{xparse}
\let\oldchapter\chapter
\RenewDocumentCommand{\chapter}{s o m}{%
  \cleardoublepage
  \IfBooleanTF{#1}
    {\oldchapter*{#3}}% \chapter*
    {\IfNoValueTF{#2}
       {\oldchapter{#3}}% \chapter{..}
       {\oldchapter[#2]{#3}}% \chapter[.]{..}
    }
  \thispagestyle{chapter}% Special \chapter-only page style
}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\sffamily\normalsize\bfseries \ #1}{}} % Chapter text font settings
\renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize\thesection\hspace{5pt}#1}{}} % Section text font settings
\fancyhf{} \fancyhead[LE,RO]{\sffamily\normalsize\thepage} % Font setting for the page number in the header
\fancyhead[LO]{\rightmark%
\begin{tikzpicture}[overlay,remember picture]
  \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
    text height=4cm,align=center,anchor=north east]
  at ($ (current page.north east) + (-0cm,-2*\thechapshift cm) $)
  {\rotatebox{90}{\parbox{4cm}{%
    \centering\textcolor{black}{\scshape\leftmark}}}};
  \end{tikzpicture}} % Print the nearest section name on the left side of odd pages
\fancyhead[RE]{\leftmark%
  \begin{tikzpicture}[overlay,remember picture]
  \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
    text height=4cm,align=center,anchor=north west]
  at ($ (current page.north west) + (-0cm,-2*\thechapshift cm) $)
  {\rotatebox{90}{\parbox{4cm}{%
    \centering\textcolor{black}{\scshape\leftmark}}}};
  \end{tikzpicture}} % Print the current chapter name on the right side of even pages
\renewcommand{\headrulewidth}{.5pt} % Width of the rule under the header
\addtolength{\headheight}{2.5pt} % Increase the spacing around the header slightly
\newcommand{\footrulecolor}[1]{\patchcmd{\footrule}{\hrule}{\color{#1}\hrule}{}{}}
\renewcommand{\footrulewidth}{.5pt}
\cfoot[\fancyplain{}{}] {\fancyplain{}{\footnotesize\bfseries{Center Foot}}} \lfoot[\fancyplain{}{}]
{\fancyplain{}{\footnotesize\bfseries\itshape{Left Foot}}}
\rfoot[\fancyplain{}{}]
{\fancyplain{}{\footnotesize\bfseries\itshape{Right Foot}}}
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}} % Style for when a plain pagestyle is specified


% Removes the header from odd empty pages at the end of chapters
\makeatletter
\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}
\patchcmd{\@makechapterhead}
  {\vskip 40\p@}
  {\vskip 40\p@\stepcounter{chapshift}}{}{}
\makeatother

\begin{document}
\part{Part One}
\mainmatter
\chapter[Intro]{Introduction}
\lipsum[1-7]
\section{This is how we do it}
\lipsum[1-7]

\chapter{Results}
\lipsum[1-7]

\chapter{Some Sample Code}
\lipsum[1-7]

\part{Part Two}
\appendix
\renewcommand\chaptermark[1]{\markboth{\sffamily\normalsize\bfseries \appendixname~\thechapter}{}}
\chapter{This is Appendix A}
\lipsum[1-7]

\chapter{This is Appendix B}
\lipsum[1-7]

\end{document}

当然,另一种选择是仅重新定义plain页面样式以满足您的需求,因为每个页面都\chapter使用\thispagestyle{plain}第一页。这可以使用

\fancypagestyle{plain}{%
  % Your page style settings here...
}

有了这个,您就不需要重新定义\chapter

相关内容