我正在尝试删除标题中的部分名称。我正在使用fancyhdr
包。当我尝试在中指定新文本时\lhead{}
,文本只是覆盖在部分名称上。PS 3 小时的谷歌搜索没有帮助。
这是我想要运行的代码部分。
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Student ID: 1123123/1}
\chead{University}
\rhead{}
\lfoot{}
\cfoot{}
\rfoot{Page \thepage\ of \pageref{LastPage}}
更新:\fancyhf{}
不起作用-没有任何变化。
由 Speravir 编辑 – 示例取自http://pastebin.com/W6V9GUCs
(OP 提供的链接对 Gonzalo 的回答的评论):
\documentclass{report}
\usepackage[a4paper]{geometry}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{fullpage, graphicx, wrapfig, subcaption, setspace}
\usepackage[T1]{fontenc}
\usepackage[font=small, labelfont=bf]{caption}
\usepackage{fourier}
\usepackage[protrusion=true, expansion=true]{microtype}
\usepackage[english]{babel}
\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}
\onehalfspacing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HEADER & FOOTER
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{Student ID: 1123123/1}
\fancyhead[C]{University}
\fancyfoot[R]{Page \thepage\ of \pageref{LastPage}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TITLE PAGE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\title{ \normalsize \textsc{SUBTITLE}
\\ [2.0cm]
\HRule{0.5pt} \\
\LARGE \textbf{\uppercase{TITLE}}
\HRule{2pt} \\ [0.5cm]
\normalsize \today
}
\date{}
\author{\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\
SID: \\
University \\
Department of Life Sciences
}
\maketitle
\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% BODY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{\textsc{SECTION}}
\end{document}
答案1
要清除页眉和页脚中的所有预定义字段,请\fancyhf{}
在分配页眉和页脚之前使用。此外,最好使用现代语法\fancyhead
, \fancyfoot
:
\documentclass{article}
\usepackage[a5paper]{geometry}% just for the example
\usepackage{lastpage}
\usepackage{fancyhdr}
\usepackage{lipsum}% just to generate text for the example
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{Student ID: 1123123/1}
\fancyhead[C]{University}
\fancyfoot[R]{Page \thepage\ of \pageref{LastPage}}
\begin{document}
\section{Test Section}
\lipsum[1-40]
\end{document}
在提供 MWE 后,很明显问题出在fullpage
包的使用上没有选项headings
;由于使用了页眉/页脚,并且未传递选项,因此页眉和文本区域重叠。解决方案是fullpage
按以下方式加载
\usepackage[header]{fullpage}
顺便说一句,由于该geometry
包也被使用,我认为存在一些冗余;您可以只使用其中一个包,具体取决于所需的页面布局。
我还对 MWE 提供的文档做了一些其他更改;特别是,我使用该sectsty
包将小型大写字母用作章节标题(这是手动完成的),并抑制了几个连续\\
命令的错误使用(产生了未满的坏框)。
我还建议不要滥用\title
和\author
命令来设计完整的标题页(例如,这可能会对书签产生不良影响),而是设计自定义的标题页。
显示所提到的变化的代码:
\documentclass{report}
\usepackage[a4paper]{geometry}
\usepackage[myheadings]{fullpage}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{graphicx, wrapfig, subcaption, setspace}
\usepackage[T1]{fontenc}
\usepackage[font=small, labelfont=bf]{caption}
\usepackage{fourier}
\usepackage[protrusion=true, expansion=true]{microtype}
\usepackage[english]{babel}
\usepackage{sectsty}
\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}
\onehalfspacing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HEADER & FOOTER
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagestyle{fancy}
\fancyhf{}
\setlength\headheight{12pt}
\fancyhead[L]{Student ID: 1123123/1}
\fancyhead[C]{University}
\fancyfoot[R]{Page \thepage\ of \pageref{LastPage}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TITLE PAGE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{\normalsize \textsc{SUBTITLE}
\\[2.0cm]
\HRule{0.5pt} \\
\LARGE \textbf{\MakeUppercase{TITLE}}
\HRule{2pt} \\[0.5cm]
\normalsize\today\vspace*{10\baselineskip}
}
\date{}
\author{
SID: \\
University \\
Department of Life Sciences}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Section title formatting
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sectionfont{\scshape}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% BODY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\maketitle
\newpage
\section*{Section}
\end{document}