如何使用 fancyhdr 刪除特定頁面標題中的部分標題但保留頁碼?

如何使用 fancyhdr 刪除特定頁面標題中的部分標題但保留頁碼?

幾天以來,我一直試圖刪除頁面上的標題,但保留頁碼。這是我的工作範例。問題是,當我使用:刪除標題時 \thispagestyle{plain},它也會刪除頁碼。除了缺少數字之外,我的第一頁工作正常。第二頁是正確的。

\documentclass[a4paper,11pt]{article}
\usepackage[ngerman]{babel} 
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markboth{#1}{}} % set the \leftmark
\fancyhf{}
\fancyhead[L]{\leftmark} % 1. sectionname
\fancyfoot[C]{\thepage}
\fancypagestyle{plain}{%
\fancyhf{}%
\renewcommand{\headrulewidth}{0.0pt}%
}
\begin{document}
\section{Titel}
\thispagestyle{plain}
\lipsum[2-10]
\end{document}

答案1

當您發出時,\fancyhf{}它會清除頁首和頁尾。因此,在重新定義樣式時plain,您將清除存在的任何頁首和頁尾。透過包含\fancyfoot[C]{\thepage}作為重新定義的一部分來重新建立頁腳:

\documentclass{article}
\usepackage{lipsum,fancyhdr}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markboth{#1}{}} % set the \leftmark
\fancyhf{}% Clear header/footer
\fancyhead[L]{\leftmark} % 1. sectionname
\fancyfoot[C]{\thepage}
\fancypagestyle{plain}{% Redefine plain pages tyle
  \fancyhf{}% Clear header/footer
  \renewcommand{\headrulewidth}{0.0pt}%
  \fancyfoot[C]{\thepage}
}
\begin{document}
\section{Titel}
\thispagestyle{plain}
\lipsum[2-10]
\end{document}

相關內容