11

I am trying to remove section names in headers. I am using fancyhdr package. When I try to specify new text in \lhead{}, text is just overlayed on section name. P.S. 3 hours of googling did not help.

Here is the section of code that I want to make work.

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Student ID: 1123123/1}
\chead{University}
\rhead{}
\lfoot{}
\cfoot{}
\rfoot{Page \thepage\ of \pageref{LastPage}}

UPDATE: \fancyhf{} is not working - nothing changes.

Edit by Speravir – Example taken from http://pastebin.com/W6V9GUCs
(link given by OP in comment to Gonzalo’s answer):

\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}
Moriambar
  • 11,466

1 Answers1

17

To clear all predefined fields in the header and footer, use \fancyhf{} before assigning your headers and footers. Also, it's preferable to use the modern syntax \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}

enter image description here

After a MWE was provided, it was clear that the problem was the use of the fullpage package without the headings option; since headers/footers were used and the option was not passed, the header and the text area overlapped. The solution is then to load fullpage in the following manner

\usepackage[header]{fullpage}

By the way, since the geometry package is also used, I think there's some redundancy; you can use only one of those packages, depending on the desired page layout.

I also made some other changes to the document provided as MWE; particularly, I used the sectsty package to use small caps for the section titles (this was being made manually), and suppressed the incorrect use of several consecutive \\ commands (producing underfull bad boxes).

I would also suggest not (ab)using the \title and \author commands to design a full titlepage (this could have undesired effects in bookmarks, for example), but to design a customized titlepage.

The code showing the changes mentioned:

\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}
Moriambar
  • 11,466
Gonzalo Medina
  • 505,128
  • How did you produce this image with two pages on the same file? – Sigur Apr 05 '13 at 02:10
  • @Sigur I produce all my images by opening the generated PDF document in Okular; then I zoom them (in or out according to the case), and use the "Selection" tool to select the region I want to copy here. – Gonzalo Medina Apr 05 '13 at 02:12
  • But to see two pages I guess that the soon is to small. But your image looks like normal size! – Sigur Apr 05 '13 at 02:13
  • 1
    @Sigur Ah, take into account that in this case I used a5paper; the zooming was 118.91%. – Gonzalo Medina Apr 05 '13 at 02:14
  • That's the point! Now everything is clear. Thanks. – Sigur Apr 05 '13 at 02:15
  • http://pastebin.com/W6V9GUCs - here is my .tex file. Your example works as a separate .tex, but not when I replicate it within my example. In the attached .tex section name is overlayed even if I use \fancyhf{}. – Arslan Atajanov Apr 05 '13 at 02:15
  • 2
    @doc please see my updated answer; what you were seeing is was not a header; was actually the title of your section. Don't load the fullpage package; to change the page layout, use the geometry package instead. I did some other changes to your document to prevent bad boxes; in some minutes I'll add some explanations. – Gonzalo Medina Apr 05 '13 at 02:23
  • 1
    @doc please see my updated answer; I added some other modifications (particularly to the section title formatting) and added the headings option to fullpage in case you decide to keep using it. I also added some explanations. – Gonzalo Medina Apr 05 '13 at 02:50