從部分頁面中刪除花俏的樣式

從部分頁面中刪除花俏的樣式

我正在使用 fancyhdr 包來設定論文的頁首和頁尾。我最近添加了 LaTeX \parts,並為此定義了一個稱為“partpagestyle”的頁面樣式。正如下面的 MWE 所示,「onlycount」樣式正確刪除了每章首頁上的標題。我已經定義了“partpagestyle”來清除格式fancyhdr,但它沒有達到預期的結果。我已仔細閱讀手冊(http://texdoc.net/texmf-dist/doc/latex/fancyhdr/fancyhdr.pdf)無濟於事。我在這裡做錯了什麼?

\documentclass[10pt]{report}
\usepackage{lipsum}
\usepackage{fancyhdr}

% Clear everything on part pages
\fancypagestyle{partpagestyle}
{
\fancyhf{}
}
% First page of chapter style
\fancypagestyle{onlycount}
{
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\renewcommand\footrulewidth{0pt}
\fancyfoot[C]{\thepage}
}
\fancypagestyle{plain}{
\lhead[\rm\thepage]{\fancyplain{}{\nouppercase{\sl{\bf{\leftmark}}}}}
\rhead[\rm\thepage]{\fancyplain{}{\nouppercase{\sl{\bf{\rightmark}}}}}
\chead{}\lfoot{}\rfoot{}\cfoot{}
\renewcommand{\headrulewidth}{0.1mm}%
\fancyfoot[C]{\thepage}%
}
\pagestyle{plain}

\begin{document}

\begin{titlepage}
\huge \bfseries Thesis
\end{titlepage}

\chapter{Introduction}\thispagestyle{onlycount}
\lipsum[1-3]
\section{Motivation}
\lipsum[1-3]

\part{Some Part}
%\thispagestyle{partpagestyle}
%\thispagestyle{partpagestyle}

\chapter{Second Chapter}\thispagestyle{onlycount}
\lipsum[1-9]

\end{document}

答案1

巨集的設定中總是有一個,因此使用標題厚度規則重新定義\part樣式report.cls將顯示這樣的一個。\thispagestyle{plain}plain0.1mm

\fancyhf{}只清除頁首和頁尾的各個字段,但是不是頁首或頁尾規則。為了澄清這一點,我添加了\renewcommand{\headrulewidth}{0pt}定義partpagestyle

此程式碼修補了\part要使用的命令partpagestyle,而不是plain

\documentclass[10pt]{report}
\usepackage{lipsum}
\usepackage{fancyhdr}

% Clear everything on part pages
\fancypagestyle{partpagestyle}
{%
  \fancyhf{}
  \renewcommand{\headrulewidth}{0pt}
}
% First page of chapter style
\fancypagestyle{onlycount}
{
  \fancyhf{}
  \renewcommand\headrulewidth{0pt}
  \renewcommand\footrulewidth{0pt}
  \fancyfoot[C]{\thepage}
}

\fancypagestyle{plain}{
  \lhead[\rm\thepage]{\fancyplain{}{\nouppercase{\textsl{\bfseries{\leftmark}}}}}
  \rhead[\rm\thepage]{\fancyplain{}{\nouppercase{\textsl{\bfseries{\rightmark}}}}}
  \chead{}\lfoot{}\rfoot{}\cfoot{}
  \renewcommand{\headrulewidth}{0.1mm}%
  \fancyfoot[C]{\thepage}%
}
\usepackage{xpatch}
% Patch the `\thispagestyle` code within `\part    
\xpatchcmd{\part}{\thispagestyle{plain}}{\thispagestyle{partpagestyle}}{}{}
\pagestyle{fancy}

\begin{document}

\begin{titlepage}
\huge \bfseries Thesis
\end{titlepage}

\chapter{Introduction}\thispagestyle{onlycount}
\lipsum[1-3]
\section{Motivation}
\lipsum[1-3]

\part{Some Part}


\thispagestyle{onlycount}
\chapter{Second Chapter}
\lipsum[1-9]

\end{document}

在此輸入影像描述

答案2

這是一個方法

\documentclass[10pt]{report}
\usepackage{lipsum}
\usepackage{fancyhdr}

\fancyhf{}
\lhead{\nouppercase{\textsl{\bfseries{\leftmark}}}}
\rhead{\nouppercase{\textsl{\bfseries{\rightmark}}}}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.1mm}
\pagestyle{fancy}

\usepackage{xpatch}

\xpatchcmd{\part}{\thispagestyle{plain}}{\thispagestyle{empty}}{}{}

\begin{document}

\begin{titlepage}
\huge \bfseries Thesis
\end{titlepage}

\chapter{Introduction}
\lipsum[1-3]
\section{Motivation}
\lipsum[1-3]

\part{Some Part}

\chapter{Second Chapter}
\lipsum[1-9]

\end{document}

相關內容