1

I need to write a LaTeX document that should have the following page specification:

  • Text Height: 240 mm & Text Width: 160 mm

  • Header with top Margin: 30 mm & Footer with Bottom margin: 27mm

  • Left Margin: 30 mm & Right Margin: 25 mm

Accordingly, I wrote the code which goes like this:

\documentclass[12pt]{report}
\usepackage[english]{babel}
\usepackage[breaklinks=true]{hyperref}
\usepackage{natbib,graphicx,mathtools,color,cleveref,xfrac,subcaption,multirow,multicol,mathptmx,lipsum}
\usepackage[shortlabels]{enumitem}
\usepackage{floatpag}\floatpagestyle{empty}
\crefname{equation}{Eq.}{Eqs.}
\crefname{figure}{Fig.}{Figs.}
\crefname{section}{Sect.}{Sects.}
\crefname{subsection}{Sect.}{Sects.}
\crefname{table}{Tab.}{Tabs.}
\linespread{1.5}

\usepackage{fancyhdr}
\pagestyle{fancy}

%\usepackage{fancyhdr}
%\pagestyle{fancy}
%\fancyhf{}
%\fancyhead[RO,RE]{\itshape \nouppercase Chapter \arabic{chapter} \itshape \nouppercase Section \arabic{section}}
%\rhead{\chaptername \thechapter \thesection}

\usepackage[textheight=280mm,textwidth=160mm,top=30mm,bottom=27mm,left=30mm,right=20mm]{geometry} % To set the page layout
\setlength{\parskip}{2.5pt}
\setlength{\parindent}{12mm}
\begin{document}
    \begin{titlepage}
    \begin{center}
        \vspace*{1cm}       
        \textbf{Thesis Title}
        \vspace{0.5cm}
        Thesis Subtitle
        \vspace{1.5cm}
        \textbf{Author Name}
        \vfill
        A thesis presented for the degree of Doctor of Philosophy
        \vspace{0.8cm}
        Department Name\\
        University Name\\
        Country\\
        Date
    \end{center}
    \end{titlepage}
    \addcontentsline{toc}{section}{\numberline{}Acknowledgement}
    \section*{Acknowledgement}  
    \lipsum[1-5]
    \tableofcontents
    \chapter{111111111} 
    \lipsum[1-5]
    \section{sec111111111-1}    
    \lipsum[1-20]
    \section{sec111111111-2}    
    \lipsum[1-20]   
    \chapter{222222222} 
    \lipsum[1-5]
    \section{sec222222222-1}    
    \lipsum[1-20]
    \section{sec222222222-2}    
    \lipsum[1-20]   
    \chapter{333333333} 
    \lipsum[1-5]
    \section{sec333333333-1}    
    \lipsum[1-20]
    \section{sec333333333-2}    
    \lipsum[1-20]   
    \chapter{444444444} 
    \lipsum[1-5]
    \section{sec444444444-1}    
    \lipsum[1-20]
    \section{sec444444444-2}    
    \lipsum[1-20]   
    \chapter{555555555} 
    \lipsum[1-5]
    \section{sec555555555-1}    
    \lipsum[1-20]
    \section{sec555555555-2}    
    \lipsum[1-20]   
    \chapter{666666666} 
    \lipsum[1-5]
    \section{sec666666666-1}    
    \lipsum[1-20]
    \section{sec666666666-2}    
    \lipsum[1-20]   
    \chapter{777777777} 
    \lipsum[1-5]
    \section{sec777777777-1}    
    \lipsum[1-20]
    \section{sec777777777-2}    
    \lipsum[1-20]
\end{document}
  1. I tried to vary Text Height and Text Width check whether any changes is occurring or not. But I could not find any. E.g. I changed text-height 180, 240 and 280 also I varied text-width to 120, 160 and 200. Is its because I have given header/footer size and left/right margin?

  2. When I am using: \usepackage{fancyhdr}, \pagestyle{fancy}, what I could see in the header is this:

q2

But what I would like to see is only like this: Chapter 1, Section 1.2 and that too in right side of header? How can I get this with the usage of \usepackage{fancyhdr}, \pagestyle{fancy}?

  1. When remove the above code and then introduce the code:

    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \fancyhf{}
    \fancyhead[RO,RE]{\itshape \nouppercase Chapter \arabic{chapter} \itshape \nouppercase Section \arabic{section}}
    \rhead{\chaptername \thechapter \thesection}
    

the header get's modified to q3

Please note that there is no space between Chapter and number 1. How to add space in between them?

  1. Furthermore, this comes in acknowledgement page and table of contents also.

q4-1

q4-2

How to get rid of this thing?

  1. Additionally, I have added this line thinking that section number will appear. It appeared, but not I the fashion that I require (kindly see question 2), which also found it’s way into acknowledgments and table of contents:

    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \fancyhf{}
    \rhead{\chaptername \thechapter \thesection}
    

q5

  1. The Chapter number and Section number (e.g., Chapter 2, Section 3) is to be printed on even numbered page headers and Section title on the odd numbered page header. How do we accomplish it? I tried with code:

    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \fancyhf{}
    \fancyhead[RO,RE]{\itshape \nouppercase Chapter \arabic{chapter} \itshape \nouppercase Section \arabic{section}}
    

But this does not help me. Any help in this regard will be highly appreciated.

  • You could just replace the header after each \chapter and \section, or you could modify \@makechapterhead and \section to do it automatically. – John Kormylo Dec 31 '18 at 14:27
  • @JohnKormylo Can you just elaborate? – sreeraj t Jan 1 at 2:12
3

In order to get fancyhdr to differentiate between even and odd pages you need to specify a [twoside] document (default for report is oneside). Note that this also changes the margins. Alternatively you could do your own \ifodd\value{page} test.

\documentclass[12pt,twoside]{report}
\usepackage[english]{babel}
\usepackage[breaklinks=true]{hyperref}
\usepackage{natbib,graphicx,mathtools,color,cleveref,xfrac,subcaption,multirow,multicol,mathptmx,lipsum}
\usepackage[shortlabels]{enumitem}
\usepackage{floatpag}\floatpagestyle{empty}
\crefname{equation}{Eq.}{Eqs.}
\crefname{figure}{Fig.}{Figs.}
\crefname{section}{Sect.}{Sects.}
\crefname{subsection}{Sect.}{Sects.}
\crefname{table}{Tab.}{Tabs.}
\linespread{1.5}

\newcommand{\sectiontitle}{}% reserve global name

\usepackage{fancyhdr}
\fancyhead{}% clear default headers
\fancyhead[RE]{\ifnum\value{section}=0\relax
  \else \chaptername~\thechapter~Section~\thesection% No \sectionname defined
  \fi}
\fancyhead[LO]{\ifnum\value{section}=0\relax
  \else \sectiontitle
  \fi}
\pagestyle{fancy}

\makeatletter% modify section to record title
\let\oldsection=\section
\def\section{\@ifnextchar*{\oldsection}{\@section}}% handle \section*
\newcommand{\@section}[2][\empty]{% optional short title
  \ifx\empty#1\relax
    \def\sectiontitle{#2}%
    \oldsection{#2}%
  \else
    \def\sectiontitle{#1}%
    \oldsection[#1]{#2}%
  \fi}
\makeatother

\usepackage[textheight=280mm,textwidth=160mm,top=30mm,bottom=27mm,left=30mm,right=20mm]{geometry} % To set the page layout
\setlength{\parskip}{2.5pt}
\setlength{\parindent}{12mm}
\begin{document}
    \begin{titlepage}
    \begin{center}
        \vspace*{1cm}       
        \textbf{Thesis Title}
        \vspace{0.5cm}
        Thesis Subtitle
        \vspace{1.5cm}
        \textbf{Author Name}
        \vfill
        A thesis presented for the degree of Doctor of Philosophy
        \vspace{0.8cm}
        Department Name\\
        University Name\\
        Country\\
        Date
    \end{center}
    \end{titlepage}
    \addcontentsline{toc}{section}{\numberline{}Acknowledgement}
    \section*{Acknowledgement}  
    \lipsum[1-5]
    \tableofcontents
    \chapter{111111111}
    \lipsum[1-5]
    \section{sec111111111-1}   
    \lipsum[1-20]
    \section{sec111111111-2}    
    \lipsum[1-20]   
    \chapter{222222222} 
    \lipsum[1-5]
    \section{sec222222222-1}    
    \lipsum[1-20]
    \section{sec222222222-2}    
    \lipsum[1-20]   
    \chapter{333333333} 
    \lipsum[1-5]
    \section{sec333333333-1}    
    \lipsum[1-20]
    \section{sec333333333-2}    
    \lipsum[1-20]   
    \chapter{444444444} 
    \lipsum[1-5]
    \section{sec444444444-1}    
    \lipsum[1-20]
    \section{sec444444444-2}    
    \lipsum[1-20]   
    \chapter{555555555} 
    \lipsum[1-5]
    \section{sec555555555-1}    
    \lipsum[1-20]
    \section{sec555555555-2}    
    \lipsum[1-20]   
    \chapter{666666666} 
    \lipsum[1-5]
    \section{sec666666666-1}    
    \lipsum[1-20]
    \section{sec666666666-2}    
    \lipsum[1-20]   
    \chapter{777777777} 
    \lipsum[1-5]
    \section{sec777777777-1}    
    \lipsum[1-20]
    \section{sec777777777-2}    
    \lipsum[1-20]
\end{document}
  • many thanks for the answer. But could you please explain the usage of the commands starting from \newcommand{\sectiontitle}{} till \makeatother? Also, there is a line that apperas on top of acknowledgement and table of contents. How to get rid it? Also, I do have 10 pages of bibliography and I want to write 'bibliography' in each pages. How can one accomplish this? – sreeraj t Jan 2 at 4:33
  • The \ifnum \else \fi structure is plain TeX, and ~ is an unbreakable space. You really should get a copy of the TeXbook by Knuth, if for no other reason than to be able to read the LaTeX souce code. For the biography, the easy solution is to redefine the headers on the first page of the biography, they move the above header definitions to the fist page of the first chapter. – John Kormylo Jan 2 at 14:36
  • Actually, the \value{section}=0 test was to handle the case where the first \section didn't come until several pages after \chapter. That it also suppressed the table of contents headers was incidental. – John Kormylo Jan 2 at 14:49
  • thank for the answer. I tried with your suggestion. I have put \fancyhead[L]{this is chapter seven} after \section{sec666666666-2}\lipsum[1-20], but the header 'this is chapter seven' appears on page 77 too instead of 'sec666666666-2'. I could solve this problem by inserting \newpage before \fancyhead[L]{this is chapter seven}. But i am curious to know why this is happening?? – sreeraj t Jan 3 at 14:36
  • Header and footers are added after the page is complete. – John Kormylo Jan 3 at 17:01

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.