1

I am trying to create a template for my PhD thesis. I liked the way Yo' has shown the page numbers in a box [ Formatting page number (fancyhdr?) ]. I have tweaked his code little bit and to add the Chapter number and the page numbers. However, I have following two problems.

  1. In my front matter I see the box with chapter number zero and roman number two, which is not desired. I would prefer to not to display any numbers (or box) until my first chapter begins.

enter image description here

  1. As you can see in figure below that on the first page of the chapter, page number is displayed on the bottom of the page. I would like to display the box with chapter number and page number also next to the heading of the chapter.

enter image description here

Following is my code. I would really appreciate your help. Thanks in advance. :)

\documentclass[11pt,openright,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{pdfpages}
\usepackage[paperheight=25cm,paperwidth=17.6cm,left=2cm,right=2cm,top=2cm,bottom=2cm, footskip=1cm]{geometry}%
\usepackage[a4, cam, center]{crop}
\usepackage{lipsum}
\usepackage{indentfirst}
\setlength{\parindent}{1cm}
\usepackage{CormorantGaramond}
\usepackage[T1]{fontenc}
\usepackage{caption} 
\captionsetup[table]{skip=8pt}
\usepackage{tikz}

\renewcommand{\baselinestretch}{1.1}
\newcommand*\chem[1]{\ensuremath{\mathrm{#1}}}
\renewcommand{\theequation}{Eq. \arabic{equation}}

\usepackage{titlesec}
\titleformat{\chapter}[hang]{\centering\Huge\bfseries}{}{0cm}{}



%%
\usepackage{fancyhdr}
%\usepackage{lastpage}
\fancyhf{}
\fancyhead[LE,RO]{{\ooalign{%
\color{black!60!white}% background box color
\rule[0.05in]{0.7in}{1in}% background box raise, width, height
\cr
\hfil\strut\raisebox{0.25in}{% number raise
\sffamily\bfseries\color{white}% number color
\Huge% number fontsize
\thechapter
\kern0.1em% distance number-bar
\rule{1pt}{1.4ex}% bar size
\kern0.15em% distance bar-totalnumber
\large% totalnumber fontsize
\thepage}\hfil
}}}
\fancyheadoffset[LE,RO]{0.8in}% protrusion 
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}


\makeatother



\pagenumbering{roman}

\begin{document}

\begin{titlepage}
\begin{center}
    \vspace*{5cm}
    \line(1,0){250}\\
    \huge{Thesis Title}
    \line(1,0){250}\\
    \vspace*{5cm}
    {\Large Name}
\end{center}
\end{titlepage}

\tableofcontents


\chapter{Chapter 1}
\pagenumbering{arabic}
\setcounter{page}{1}
\lipsum[1-10]

\chapter{Chapter 2}
\lipsum[1-10]


\chapter{Chapter 3}
\lipsum[1-10]

\chapter{Chapter 4}
\lipsum[1-10]


\end{document}
1
\documentclass[11pt,openright,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{pdfpages}
\usepackage[paperheight=25cm,paperwidth=17.6cm,left=2cm,right=2cm,top=2cm,bottom=2cm, footskip=1cm]{geometry}%
\usepackage[a4, cam, center]{crop}
\usepackage{lipsum}
\usepackage{indentfirst}
\setlength{\parindent}{1cm}
\usepackage{CormorantGaramond}
\usepackage[T1]{fontenc}
\usepackage{caption} 
\captionsetup[table]{skip=8pt}
\usepackage{tikz}
%\usepackage{lineno}
%\linenumbers
\usepackage{xcolor}
\usepackage{framed}
\usepackage{titletoc}
\usepackage{etoolbox}
\usepackage{lmodern}

\renewcommand{\baselinestretch}{1.1}
\newcommand*\chem[1]{\ensuremath{\mathrm{#1}}}
\renewcommand{\theequation}{Eq. \arabic{equation}}


%%
\usepackage{fancyhdr}
% for remving all styles from front matter
\fancypagestyle{style1}{
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
}
% for adding boxes with chapter and page numbers
\fancypagestyle{style2}{
\fancyhf{}
\fancyhead[LE,RO]{{\ooalign{%
\color{black!60!white}% background box color
\rule[0.05in]{0.7in}{1in}% background box raise, width, height
\cr
\hfil\strut\raisebox{0.25in}{% number raise
\bfseries\color{white}% number color
\Huge% number fontsize
\thechapter
\kern0.1em% distance number-bar
\rule{1pt}{1.4ex}% bar size
\kern0.15em% distance bar-totalnumber
\large% totalnumber fontsize
\thepage}\hfil
}}}
\fancyheadoffset[LE,RO]{0.8in}% protrusion 
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{style2}}{}{}

\pagestyle{style1}

\begin{document}


%\begin{titlepage}
%\begin{center}
%   \vspace*{5cm}
%   \line(1,0){250}\\
%   \huge{Thesis Title}
%   \line(1,0){250}\\
%   \vspace*{5cm}
%   {\Large Name}
%\end{center}
%\end{titlepage}

\tableofcontents
\thispagestyle{empty}



\chapter{Introduction}
\pagestyle{style2}
\pagenumbering{arabic}
\setcounter{page}{1}
\section{1}\lipsum[1-10]
\section{2}\lipsum[1-10]

\chapter{Experimental}
\pagestyle{style2}
\lipsum[1-10]



\chapter{Chapter 3}
\pagestyle{style2}
\lipsum[1-10]

\chapter{Appendix 3A}

\chapter{Chapter 4}
\pagestyle{style2}
\lipsum[1-10]


\end{document}

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.