0

For my thesis I wish to alternate the header for even and odd pages like this template. I looked at the code of that template, but it was a bit too complicated for me to apply it to my own file.

On the even pages I want the page number on the left side and the subsection name on the right side. On the odd pages I want the page number on the right side and the section name on the left side. Lastly, I want pages where a new section starts to not have a header and to be able to specify other pages where I do not wish to have a header.

I tried the following using fancyhdr with the article as documentclass:

\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[LO]{\nouppercase{\rightmark}}
\fancyhead[RE]{\nouppercase{\leftmark}}
\fancyhead[LE,RO]{\thepage}
\pagestyle{fancy}

However, instead of the name of the subsection it returns 'Table of Contents' for the even pages until the page where the references start. For the odd pages it works fine for the section name. How can I change this behavior? Full preamble looks like this:

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{amsmath}

% For tables
\usepackage{array}
\usepackage{booktabs}

% for having numbers aligned to the decimal point
\usepackage{siunitx}

% For captions
\usepackage[labelfont=bf]{caption}

% Include graphics from pdf or jpg file
\usepackage{graphicx} 

% For citations
\usepackage{apacite}
\bibliographystyle{apacite}

\graphicspath{{Images/}}

\usepackage{xstring}
\usepackage{titleps}
\usepackage{subcaption} %Side by side table alignment
\usepackage{makecell} %Split table headers into multiple lines

% bold math symbols
\usepackage{bm}

\usepackage{tikz}
\usepackage[titletoc]{appendix}

% easily write third, fourth, fifth etc.
\usepackage[super]{nth}

\usepackage{tikz}
\usepackage{mathdots}
\usepackage{yhmath}
\usepackage{cancel}
\usepackage{color}
\usepackage{multirow}
\usepackage{amssymb}
\usepackage{gensymb}
\usepackage{tabularx}
\usetikzlibrary{fadings}

% Change contents to table of contents
\renewcommand{\contentsname}{Table of Contents}
\renewcommand\labelitemi{$\cdot$}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\raggedbottom

\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[LO]{\nouppercase{\rightmark}}
\fancyhead[RE]{\nouppercase{\leftmark}}
\fancyhead[LE,RO]{\thepage}

\pagestyle{fancy}
  • Maybe you shouldn't load both titleps and fancyhdr, which tackle the same things. – Bernard Jun 26 '19 at 9:54
  • That didn't change anything unfortunately. Thanks for the suggestion! – bjornvandijkman Jun 26 '19 at 10:40
  • You should post a complete (yet minimal) code which reproduces the problem. – Bernard Jun 26 '19 at 12:33
0

Hello bjornvandijkman,

I cannot really reproduce your problem without having a minimal working example. It works fine for me (see my code using your preample).

Two notes:

  1. You switched the marks. So leftmark and rightmark have to be switched.
  2. Did you consider using report respectively scrreprt with chapters (that would automatically enable plain page style on pages on which the chapter starts).

It would be helpful to see your code with some of the content because I assume the error is there. Also what TeX version and OS do you use?

My examples with article

\documentclass[12pt, twoside]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{amsmath}

% For tables
\usepackage{array}
\usepackage{booktabs}

% for having numbers aligned to the decimal point
\usepackage{siunitx}

% For captions
\usepackage[labelfont=bf]{caption}

% Include graphics from pdf or jpg file
\usepackage{graphicx}

% For citations
\usepackage{apacite}
\bibliographystyle{apacite}

\graphicspath{{Images/}}

\usepackage{xstring}
\usepackage{titleps}
\usepackage{subcaption} %Side by side table alignment
\usepackage{makecell} %Split table headers into multiple lines

% bold math symbols
\usepackage{bm}

\usepackage{tikz}
\usepackage[titletoc]{appendix}

% easily write third, fourth, fifth etc.
\usepackage[super]{nth}

\usepackage{tikz}
\usepackage{mathdots}
\usepackage{yhmath}
\usepackage{cancel}
\usepackage{color}
\usepackage{multirow}
\usepackage{amssymb}
\usepackage{gensymb}
\usepackage{tabularx}
\usetikzlibrary{fadings}

% Change contents to table of contents
\renewcommand{\contentsname}{Table of Contents}
\renewcommand\labelitemi{$\cdot$}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\raggedbottom

\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[LO]{\nouppercase{\leftmark}}
\fancyhead[RE]{\nouppercase{\rightmark}}
\fancyhead[LE,RO]{\thepage}

\pagestyle{fancy}

\begin{document}
Empty page
\newpage
\tableofcontents
\newpage
\section{Introduction}

\subsection{Sub Introduction 1}

\newpage
\newpage

\subsection{Sub Introduction 2}

\newpage
\newpage

\section{Material and Methods}

\subsection{MM 1}
\newpage
foo
\newpage
foo
\newpage

\subsection{MM2}

\newpage

\section{Results}

\newpage
\newpage
foo
\newpage
foo
\newpage

\section{Discussion}
\newpage
foo
\newpage
foo
\newpage
\end{document}

and with scrreprt

\documentclass[12pt, twoside]{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{amsmath}

% For tables
\usepackage{array}
\usepackage{booktabs}

% for having numbers aligned to the decimal point
\usepackage{siunitx}

% For captions
\usepackage[labelfont=bf]{caption}

% Include graphics from pdf or jpg file
\usepackage{graphicx}

% For citations
\usepackage{apacite}
\bibliographystyle{apacite}

\graphicspath{{Images/}}

\usepackage{xstring}
\usepackage{titleps}
\usepackage{subcaption} %Side by side table alignment
\usepackage{makecell} %Split table headers into multiple lines

% bold math symbols
\usepackage{bm}

\usepackage{tikz}
\usepackage[titletoc]{appendix}

% easily write third, fourth, fifth etc.
\usepackage[super]{nth}

\usepackage{tikz}
\usepackage{mathdots}
\usepackage{yhmath}
\usepackage{cancel}
\usepackage{color}
\usepackage{multirow}
\usepackage{amssymb}
\usepackage{gensymb}
\usepackage{tabularx}
\usetikzlibrary{fadings}

% Change contents to table of contents
\renewcommand{\contentsname}{Table of Contents}
\renewcommand\labelitemi{$\cdot$}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\raggedbottom

\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[LO]{\nouppercase{\leftmark}}
\fancyhead[RE]{\nouppercase{\rightmark}}
\fancyhead[LE,RO]{\thepage}

\fancypagestyle{plain}{%
\fancyhf{}
}


\pagestyle{fancy}

\begin{document}
Empty page
\newpage
\tableofcontents
\newpage
\chapter{Introduction}

\section{Sub Introduction 1}

\newpage
\newpage

\section{Sub Introduction 2}

\newpage
\newpage

\chapter{Material and Methods}

\section{MM 1}
\newpage
foo
\newpage
foo
\newpage

\section{MM2}

\newpage

\chapter{Results}

\newpage
\newpage
foo
\newpage
foo
\newpage

\chapter{Discussion}
\newpage
foo
\newpage
foo
\newpage
\end{document}

Best regards

Jeroen

  • Hi Jeroen, your code with article gives exactly the same problem as I have. scrreprt works but results in some other formatting issues that I'm not a fan of, like how it formats the captions. I'm working on overleaf. Can you check your article code to see if behaves well on your OS? – bjornvandijkman Jun 26 '19 at 13:23
  • Solved the issue by moving the code related to fancyhdr to the top of the preamble. Interesting behavior. – bjornvandijkman Jun 26 '19 at 13:31
  • Hi bjornvandijkman, awesome you solved it! Really interesting. I tried some more things. The packages appendix and titleps affect the headings. Which makes sense because titleps also makes headings. – J-Schaefer Jun 26 '19 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.