对fancyhdr感到沮丧

Fla*_*ius 3 latex tex

我有以下tex文档:

\documentclass[a4paper,11pt,oneside]{book}
\usepackage[usenames,dvipsnames]{color}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage{lipsum}
\usepackage[left=2cm,top=3cm,right=1.5cm,bottom=2cm]{geometry}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\renewcommand{\subsectionmark}[1]{\markright{\thesubsection}{}}

\usepackage[Lenny]{fncychap}
\usepackage{thumbpdf}
\usepackage[colorlinks]{hyperref}
\setlength\marginparwidth{1cm}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhead[LO,L]{Book template}
\fancyhead[RO,R]{\rightmark}
\fancyfoot[CO,C] {\thepage}

\begin{document}
\chapter{Chapter Intro}
\lipsum
\chapter{Chapter with subsections}
\section{section foo}
\lipsum
\subsection{subsection bar}
\lipsum
\end{document}
Run Code Online (Sandbox Code Playgroud)

可以在http://www.mediafire.com/?0m5mnka32kj查看示例

在右上角:

  • 如果没有章节,如何让它显示章节标题,如第2页?
  • 如果有一个活动部分,如何使它显示部分标题,只显示部分标题(没有数字,没有子部分,子部分等),就像第4页的情况一样?

谢谢

ear*_*arl 9

你快到了!

以下两个标记应该可以解决问题:

\renewcommand{\chaptermark}[1]{\markright{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
Run Code Online (Sandbox Code Playgroud)

一定要把它们移到一个位置之后 \pagestyle{fancy}.另外一定要删除自定义\subsectionmark,除非您想在标题中使用某些子节信息.