I am a bit confused with the fancyhdr
options. I currently have this style for my headers:
MWE:
\documentclass[12pt,oneside]{book}%use oneside to ensure no blanks\
\usepackage[text={5.45in,8.5in}, left=1.5in, right=1.25in, top=1.25in, bottom=1.25in, headheight=15.91pt, centering]{geometry}
\usepackage[table,hyperref]{xcolor}
\usepackage{setspace, fancyhdr, amsmath, amssymb,amsthm, graphicx, color, lscape, longtable, booktabs, caption, wrapfig, hyperref, pdfpages, capt-of, microtype, lmodern, titlesec, tikz, lipsum}
% Ensures we put the section name/number on the left side and page number on right
\fancyhf{} % clear all header and footer fields
\pagestyle{fancy} %define page style
\pagenumbering{roman} %page numbering style: before main text
\fancyhead[L]{\nouppercase{\rightmark}}
\fancyhead[R]{\thepage}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{0.5pt} % make space for the rule
\fancypagestyle{plain}{%
\fancyhead{} % get rid of headers on plain pages
\fancyhead[R]{\thepage}
\renewcommand{\headrulewidth}{0pt} % and the line
}
\doublespacing
\newpage
\pagenumbering{arabic}
\renewcommand{\headrulewidth}{0.5pt}
\begin{document}
\chapter{Some chapter}
\section{Section I}
\lipsum[1-1]
\subsection{Subsection}
\lipsum[1-2]
\section{Section II}
\lipsum[1-2]
\subsection{Subsection One}
\lipsum[1-2]
\subsection{Subsection Two}
\lipsum[1-2]
\end{document}
\section{Section III}
\lipsum[1-2]
\subsection{Subsection for this section}
\lipsum[1-2]
\subsection{Another subsection}
\lipsum[1-2]
The current header looks like this:
1.1 Section I
This is fine for most of my sections. However for some sections, say section II in the above MWE, I would like the header to read like so:
1.2 Section II: Subsection Two
I would then like the header to switch back to the current style in the next section (Section III):
1.3 Section III
I read several posts here on fancyhdr and the section on fancyhdr in wikibooks but I am having some trouble getting it to work, especially with the colon in between. Any help would be awesome!
PS: If this is a duplicate question, could you please point me to the relevant question?
Best Answer
We redefine
\subsectionmark
to keep the title, but only when the conditional\ifsubsectioninheader
is true; in this case the header will show the information. The usual definition of\subsectionmark
is to do nothing.As an aside, notice the better method the
book
class has for switching from roman page numbering to arabic. With\frontmatter
you have also other advantages: the chapters there are not numbered, but go automatically in the table of contents.