标题中缺少章节名称(带有 fancyhdr)

标题中缺少章节名称(带有 fancyhdr)

我更改了 fancyhdr 设置,但看起来并不像我想要的那样。只需查看下面的示例并使用 pdflatex。在 pdf 的第二面,标题文本应该是:“第 1 章:我的章节名称”

\documentclass[a4paper,oneside,10pt]{report}
\usepackage{fancyhdr}

\fancypagestyle{myheader}{ 
    \fancyhead{} %clear all headers
    \fancyfoot{} %clear all footers
    \fancyhead[L]{\chaptername \ \thechapter: } %How to insert the Chapter names like "MyChapter"?
    \fancyhead[R]{\thepage}
    \renewcommand{\headrulewidth}{0.4pt} 
    \renewcommand{\footrulewidth}{0.0pt}    
}

\begin{document}
\pagestyle{myheader}

\chapter{MyChaptername}
This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... 
This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... 
This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... 
This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... 
This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is  

\subsection{MySubsection}
This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... 
This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... 
This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... 
This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... This is some Text... 
\end{document}

有人能帮助我吗?

答案1

你可以简单地使用

\fancyhead[L]{\leftmark}

并重新定义\chaptermark

\renewcommand{\chaptermark}[1]{\markboth{\chaptername\ \thechapter:\ #1}{}}

平均能量损失

\documentclass[a4paper,oneside,10pt]{report}
\usepackage{fancyhdr}

\fancypagestyle{myheader}{
    \fancyhead{} %clear all headers
    \fancyfoot{} %clear all footers
    \fancyhead[L]{\leftmark} %How to insert the Chapter names like "MyChapter"?
    \fancyhead[R]{\thepage}
    \renewcommand{\headrulewidth}{0.4pt}
    \renewcommand{\footrulewidth}{0.0pt}
}
\pagestyle{myheader}
\renewcommand{\chaptermark}[1]{\markboth{\chaptername\ \thechapter:\ #1}{}}

\usepackage{lipsum} %for dummy text

\begin{document}   
\chapter{MyChaptername}
\lipsum[1-30]
\end{document} 

输出

在此处输入图片描述

相关内容