How to Add Custom Headers and Footers in LaTeX
The fix
Use the fancyhdr package. Load \usepackage{fancyhdr}, set \pagestyle{fancy}, clear defaults with \fancyhf{}, then fill the header with \lhead{}, \chead{}, \rhead{} and the footer with \lfoot{}, \cfoot{}, \rfoot{}. Use \leftmark and \rightmark for the current chapter/section, and \thepage for the page number.
Example
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear defaults
\rhead{\leftmark} % chapter name, right header
\lhead{My Thesis}
\cfoot{\thepage} % page number, centre footerFrequently asked questions
Why is there a line under my header?
fancyhdr draws a header rule by default. Remove it with \renewcommand{\headrulewidth}{0pt}, or set a larger value to thicken it.
How do I put the chapter title in the header?
Use \leftmark (chapter) or \rightmark (section) inside \rhead or \lhead. fancyhdr updates them automatically as the document progresses.
Related LaTeX fixes
Browse all LaTeX problems & fixes, or start with the LaTeX guide.
Try the fix in LetX
Open the editor, paste your code, and compile in seconds to see the error clear — free, in your browser.
Open LetX Free