kks32 / phd-thesis-template

A LaTeX / XeLaTeX / LuaLaTeX PhD thesis template for Cambridge University Engineering Department (CUED)
http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/ThesisStyle/
MIT License
820 stars 392 forks source link

How to create header of chapter name instead of section name #249

Closed angoodkind closed 1 year ago

angoodkind commented 1 year ago

This is related to issue #77. How would you define a custom header that just uses the chapter name, not the section name?

GR8DAN commented 1 year ago

You need to learn the joys (pain) of the fancyhdr package. See line 730 onwards in PhDThesisPSnPDF.cls. You could add a new page style option, i.e., replace lines 756 to 783 with:

% Style 3: Sets Page Number at the Top with Chapter Name and an empty footer
\fancypagestyle{PageStyleIII}{
  \renewcommand{\chaptermark}[1]{\markboth{##1}{}}
  % Clear the headers
  \fancyhf{}
  \fancyhead[RE]{\leftmark}
  \fancyhead[LO]{\leftmark}
  \fancyhead[LE,RO]{\thepage}
}

% Set Fancy Header Command is defined to Load FancyHdr after Geometry is defined
\newcommand{\setFancyHdr}{

\pagestyle{fancy}

\ifPHD@pageStyleI
  % Style 1: Sets Page Number at the Top and Chapter/Section Name on LE/RO
  \pagestyle{PageStyleI}
\else
  \ifPHD@pageStyleII
    % Style 2: Sets Page Number at the Bottom with Chapter/Section Name on LO/RE
    \pagestyle{PageStyleII}
  \else
    \ifPHD@pageStyleIII
      % Style 3: Sets Chapter Name on LO/RE
      \pagestyle{PageStyleIII}
    \else
      % Default Style: Sets Page Number at the Top (LE/RO) with Chapter/Section Name
      % on LO/RE and an empty footer
      \renewcommand{\chaptermark}[1]{\markboth {##1}{}}
      \renewcommand{\sectionmark}[1]{\markright{\thesection\ ##1}}
      \fancyhf{}
      \fancyhead[LO]{\nouppercase \rightmark}
      \fancyhead[LE,RO]{\bfseries\thepage}
      \fancyhead[RE]{\nouppercase \leftmark}
    \fi  
  \fi
\fi
}

Then add this below line 141:

\newif\ifPHD@pageStyleIII\PHD@pageStyleIIIfalse % Set Page StyleIII
\DeclareOption{PageStyleIII}{\PHD@pageStyleIIItrue}

Then pass PageStyleIII as an option to the \documentclass (line 4 in thesis.tex)

angoodkind commented 1 year ago

Thank you so much for this! The only issue is that it doesn't seem to work with oneside printing, as the header only goes across part of the page. (Sorry for not including that information in the original issue.)

GR8DAN commented 1 year ago

The header/footer styling options are written for two-sided output for printing. A test for oneside or twoside can be used to add support for one-sided documents. For example, for my previous Style 3 example:

% Style 3: Sets Page Number at the Top with Chapter Name and an empty footer
\fancypagestyle{PageStyleIII}{
  \renewcommand{\chaptermark}[1]{\markboth{##1}{}}
  % Clear the headers
  \fancyhf{}
  \if@oneside
    \fancyhead[L]{\nouppercase \leftmark}
    \fancyhead[R]{\nouppercase \thepage}  
  \else
    \fancyhead[RE]{\nouppercase \leftmark}
    \fancyhead[LO]{\nouppercase \leftmark}
    \fancyhead[LE,RO]{\thepage}
  \fi
}

However, the oneside option cause fancyhdr warnings for the other styles. I see you have commented on issue #133 which is in the develop branch and attempts to address that issue.

angoodkind commented 1 year ago

Ok, got it! Since I'm about to submit my thesis, I'm not going to play around with the development branch. I'll wait for it to move into production. Thanks so much for your help!