I am trying to use fancyhdr, but I can't get it to not show the section and to keep the normal case for title and 'Chapter'.
How can I have my heading to be "Chapter 1. The title of the chapter" (left aligned on all pages)
fancyhdrheader-footer
I am trying to use fancyhdr, but I can't get it to not show the section and to keep the normal case for title and 'Chapter'.
How can I have my heading to be "Chapter 1. The title of the chapter" (left aligned on all pages)
Try this code:
\documentclass{book}
\usepackage{fancyhdr}
\fancyhf{}
\lhead{\itshape BA TOPIC}
\chead{\itshape{\nouppercase{\leftmark}}}
\rhead{\thepage}
\lfoot{}
\cfoot{}
\rfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\usepackage[ocgcolorlinks]{hyperref}
\usepackage{bookmark}
\usepackage{lipsum} %% for dummy text
\begin{document}
\frontmatter
\pagestyle{plain}
%Titlepage
%\input{title.tex}
%ToC etc
\tableofcontents
\listoffigures
\listoftables
\cleardoublepage
\pagestyle{fancy}
%define header style for chapter pages and put it here
\fancypagestyle{plain}{%
\fancyhf{}
\fancyhead[L]{\itshape{BA THEMA}}
\fancyhead[C]{}
\fancyhead[R]{\thepage}
}
\mainmatter
% actual Content
\chapter{Einleitung}
\lipsum[1]
\section{Some section}
\lipsum[2-8]
\chapter{Second}
\lipsum[1]
\section{Some other section}
\lipsum
\end{document}
You can define a fancy page style like:
\fancypagestyle{myfancy}{%
\fancyhf{}
\fancyhead[L]{<your settings>}
\fancyhead[C]{<your settings>}
\fancyhead[R]{<your settings>}
\fancyfoot[L]{<your settings>}
\fancyfoot[C]{<your settings>}
\fancyfoot[R]{<your settings>}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
and use it as \pagestyle{myfancy}
. But if you want to change the page style of chapter pages, you should do it by changing the plain
style as shown above.
A couple of things:
The only reason to use this class is that you need to satisfy the institutional requirements it implements. If this is the case, changing the layout will result in your work being deemed inadmissible.
If this is not the case, you would be far better advised to use a different class. This one is quite explicit about the fact that it violates rules of good typography. It has to. The institutional requirements demand poor typography.
As it stands, your code does not compile without error. This is closely connected to the next point.
Your preamble is a mess. This makes it harder to ensure consistency, increases the chances that packages will conflict, makes weird, mysterious problems almost certain, and makes it more difficult to diagnose problems when they inevitably occur.
enumitem
and paralist
; subcaption
and subfig
.url
as well as hyperref
; graphics
as well as graphicx
.hyperref
should be loaded late.Don't typeset your entire thesis with \sloppy
unless your institution explicitly requires such a typographical monstrosity. (This is not likely: I've never heard of them requiring this one, even though they frequently require typographical monstrosities of other kinds.)
In answer to the specific question, \afterpreface
sets the page style to headings
. Redefining this command to set it to fancy
allows fancyhdr
settings to take effect:
Complete code with some more specific annotations follows. I've tried to group packages which provide similar functionality together to make it easier to see what you need and what you don't. If you don't know why you are using a package, comment it out and see if that breaks your compilation. If not, you probably can do without it.
I have, however, added fontenc
to get the T1
font encoding which is highly recommended and will get you scalable type1 fonts, as well.
\documentclass[11pt,PhD,twoside]{muthesis}
\usepackage[T1]{fontenc}% recommended
\usepackage{textcomp}
\usepackage{todonotes}
\usepackage{amsmath}
\usepackage{amstext}
% \usepackage{paralist}% enumitem provides similar functionality - stick to one interface
\usepackage{enumitem}
% tables
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{booktabs}
% captions and floats
\usepackage[font=footnotesize,labelfont=bf]{caption}
\usepackage[aboveskip=2pt]{subcaption} % aboveskipchanges spacing beten caption and figure
\captionsetup[subfigure] {justification=justified,singlelinecheck=false} %%% alignment of subfigure captions
% \usepackage{subfig}% if you are using subcaption, don't try to use subfig, too - this way lies madness
\usepackage{stackengine}
% colour, graphics, diagrams
\PassOptionsToPackage{table}{xcolor}
\usepackage{graphicx}% don't load graphics as well - this covers it all already
\usepackage{pgfplotstable}
\pgfplotstableset{col sep=comma}
\usepackage[UKenglish]{datetime}
\usepackage{parskip}
\usepackage[none]{hyphenat}
\usepackage{lscape}
% for references
% \usepackage{cite}% do you really want this as well as natbib? they are likely to fight!
\usepackage{natbib}
%\setlength{\bibhang}{5em}
\renewcommand{\bibfont}{\normalfont\small}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{listings}
\usepackage[]{titlesec}
\usepackage{fancyhdr}
% to sort out issues with urls
\usepackage[hyperindex,breaklinks]{hyperref}% load late: loads url - no need to load separately
\titleformat{\section}
{\normalfont\fontsize{13}{15}\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\fontsize{13}{15}\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\fontsize{13}{15}\bfseries}{\thesubsubsection}{1em}{}
\titleformat{\subsubsubsection}
{\normalfont\fontsize{13}{15}\bfseries}{\thesubsubsubsection}{1em}{}
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\def\afterpreface{\newpage
\pagestyle{fancy}}
\pagestyle{fancy}
\fancyhf{}
\renewcommand*\headrulewidth{0pt}
\fancyhf[leh,roh]{\thepage}
\fancyhf[loh,reh]{\slshape\leftmark}
\begin{document}
\title{A thesis}
\author{AN Author}
\school{School of}
\faculty{Faculty}
\def\wordcount{57103}
\beforeabstract
\section*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}
% \sloppy% don't do this: It applies \sloppy to the rest of your document which is almost certainly not what you want
\begin{spacing}{1.0}
\fontsize{12}{12}\normalfont% is this a requirement? Because it will give you ugly output which is hard to read
abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract abstract
\end{spacing}
\afterabstract
\prefacesection{Acknowledgements}
I would like to thank......
\afterpreface
\chapter{Introduction}
\section{Background}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\clearpage
\section{Background2}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\clearpage
\section{Background3}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\end{document}
Best Answer