0

I've been using the default "fancy" pagestyle for as long as I remember with the section as the right header and the subsection as the left header. I just dug up a document from April this year (will be an important detail later) and it looks like this (which is what I want):

enter image description here

This is where the current section is "The Set of Real Numbers" and the subsection is "Irrational Numbers".

I now recompile the same document without changing anything in the source and this shows up instead:

enter image description here

(Note there is a contents page which is where it must be getting that mark from, but previously it would never cause this to happen.)

That's why I had to get a document back from April - I've been playing with some other documents and without fail, compiling the exact same code causes the section to flip to the left and "CONTENTS" to show on the right on every page. I can't find a way to revert it to what it was before.

Really stumped here - any help would be much appreciated.

1 Answer 1

3

Set the headers using \leftmark (for \sections) and \rightmark (for \subsections):

enter image description here

\documentclass[twoside]{article}

\usepackage{fancyhdr,lipsum}
\pagestyle{fancy}

\fancyhf{}% Clear header/footer
\fancyhead[RO,LE]{\slshape\leftmark}
\fancyhead[RE,LO]{\slshape\rightmark}
\fancyfoot[C]{\thepage}

\begin{document}

\sloppy % Just for this example

\tableofcontents

\section{First section}\lipsum[1-10]
\subsection{First subsection}\lipsum[11-20]
\subsection{Second subsection}\lipsum[21-30]
\subsection{Third subsection}\lipsum[31-40]
\subsection{Last subsection}\lipsum[41-50]

\section{Second section}\lipsum[1-10]
\subsection{First subsection}\lipsum[11-20]
\subsection{Second subsection}\lipsum[21-30]
\subsection{Third subsection}\lipsum[31-40]
\subsection{Last subsection}\lipsum[41-50]

\section{Third section}\lipsum[1-10]
\subsection{First subsection}\lipsum[11-20]
\subsection{Second subsection}\lipsum[21-30]
\subsection{Third subsection}\lipsum[31-40]
\subsection{Last subsection}\lipsum[41-50]

\section{Last section}\lipsum[1-10]
\subsection{First subsection}\lipsum[11-20]
\subsection{Second subsection}\lipsum[21-30]
\subsection{Third subsection}\lipsum[31-40]
\subsection{Last subsection}\lipsum[41-50]

\end{document}
4
  • It works if I copy your code to a new document - but in any of my existing ones it still shows up as section on the left and "Contents" on the right even after I add your fancy head/foot statements there. Would anything be interfering with the marks?
    – Platehead
    Sep 29, 2017 at 3:39
  • @Platehead Try to delete the auxiliary files of your document and re-run.
    – CarLaTeX
    Sep 29, 2017 at 3:56
  • @Platehead: Then there must be some other style file you use that sets that. What does your preamble look like?
    – Werner
    Sep 29, 2017 at 4:03
  • Found it - culprit was the natbib package. No clue why it would mess with the header, and even more so why it used to be okay (I've used the same template file for a few years now haha). Thanks a lot for your help.
    – Platehead
    Sep 29, 2017 at 4:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .