0

Our university has instructions to write the thesis in a one-sided format. I am trying to place the chapter title and section title in the odd-even pages. I have succeeded (with manual inputs) in placing these along with the page number using the code from this link.

I manually put the following code in every section (of every chapter) to get this.

\pagestyle{fancy}
\newcommand\cotitle{Chapter 1 Title}
\newcommand\secco{Chapter 1, Section 1 Title}
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\fancyhead[C]{%
\ifodd\value{page}
  \small\scshape\cotitle
\else
  \small\scshape\secco
\fi }
\fancyhead[R]{\thepage\ifodd\value{page}\else\hfill\fi}

Is it possible to use \rightmark and \leftmark to get automatic chapter title (say, in the odd pages) and section title (say, in the even pages) in a one-sided thesis format?

Note that, I have 5 chapters and each containing 4-6 sections.

Any help will be highly appreciated. Thanks in advance.

  • Normally, \leftmark will be the chapter title and \rightmark will be the section title. The default is that they also contain the chapter and section number, respectively. You must redefine \chaptermark and \sectionmark if you don't want these numbers. See the fancyhdr documentation. – Pieter van Oostrum Sep 01 '22 at 18:27
  • I think you need to distinguish between LaTex oneside/twoside and the printed result where they want the margins on every page to be the same. You can get twoside to give the appearance of oneside, but I can't remember how. Hopefully somebody else can help. – Peter Wilson Sep 01 '22 at 18:32
  • @PietervanOostrum Thank you Professor for the tips. There are no issues with the numbers. I am unable to make it possible automatically. – Pinaki Prasad Kar Sep 02 '22 at 02:12
  • @PeterWilson Thanks Professor Wilson for the comment. I need the one-sided format. Somehow, I have managed to do this manually. I wonder if it can be done automatically. – Pinaki Prasad Kar Sep 02 '22 at 02:15

1 Answers1

1

As Peter Wilson said you could use a twoside document but with the same left and right margins, which can be done with the geometry package. Something like

\usepackage[leftmargin=5cm,rightmargin=5cm]{geometry}

The other way is to use a oneside document and use the \ifodd\value{page} as you have done in your code, but using \leftmark and \rightmark. This is the solution that I am offering you.

\documentclass[oneside]{report}

\usepackage{fancyhdr} \usepackage{lipsum}

\pagestyle{fancy} \newcommand\cotitle{Chapter 1 Title} \newcommand\secco{Chapter 1, Section 1 Title} \fancyhf{} \renewcommand\headrulewidth{0pt} \fancyhead[C]{% \small\scshape \ifodd\value{page} \leftmark \else \rightmark \fi} \fancyhead[L]{\ifodd\value{page}\else\thepage\fi} \fancyhead[R]{\ifodd\value{page}\thepage\fi}

\begin{document}

\chapter{Introduction}

\lipsum[1]

\section{The first section}

\lipsum[2-11]

\end{document}

enter image description here

enter image description here

  • Thanks a lot Professor Pieter for helping me with this wonderful code. I have the chapters with .tex files. It does not show the section titles. I have inserted this in the preamble. – Pinaki Prasad Kar Sep 02 '22 at 11:41
  • I don't understand this. Do you mean you don't use the \section command to define a section? Do you use \chapter commands for your chapters? – Pieter van Oostrum Sep 02 '22 at 14:40
  • I use those. But I have a separate folder (namely, Chapters) for the chapters where there are .tex files for the chapters. And in the main .tex file, I call the chapters as: \input{Chapters/Chapter1}. Here Chapter1 is the .tex file for Chapter 1. Hope you understand my problem now. Thanks. – Pinaki Prasad Kar Sep 03 '22 at 05:06
  • I could be making a mistake. But I'm not sure what's wrong. – Pinaki Prasad Kar Sep 03 '22 at 05:09
  • 1
    Using \input should not make a difference, as long as you have the normal \chapter and \section commands in these files. – Pieter van Oostrum Sep 03 '22 at 07:12
  • I have used the article class. May be that's the problem. – Pinaki Prasad Kar Sep 27 '22 at 09:03
  • @PinakiPrasadKar In your question you are talking about chapters. But the article class doesn't have chapters. – Pieter van Oostrum Sep 27 '22 at 11:09
  • Yes. The thesis has another class file (neither an article nor a report). I am not able to find the mistake. But I can now do this with the report class. – Pinaki Prasad Kar Sep 27 '22 at 16:56
  • Is that class file somewhere to be found? – Pieter van Oostrum Sep 27 '22 at 19:30
  • Professor Pieter! I am using the class file: https://github.com/bardsoftware/template-thes-iitk/blob/master/Thesis.cls with the main file in a one-sided format. – Pinaki Prasad Kar Sep 28 '22 at 14:49
  • @PinakiPrasadKar With that Thesis class it also work if you add the following line to your file: \renewcommand{\sectionmark}[1]{\markright{\thesection.~#1}} – Pieter van Oostrum Sep 28 '22 at 18:52
  • Shall I need to add/remove/change any other command? – Pinaki Prasad Kar Sep 29 '22 at 07:17
  • I don't think so. I have tried my solution with report changed to Thesis, and the command added, and that does it. But your thesis would probably be more complicated, so maybe. For example if you would want the chapter titles to appear differently in your headers, then you would also have to change \chaptermark. You could take the definition in the class file as an example. – Pieter van Oostrum Sep 29 '22 at 11:45
  • Professor Pieter! Thank you for your valuable comments. Is there any other source that can help me in this regard? That is a one-sided thesis template with an automatic chapter and section title. – Pinaki Prasad Kar Sep 30 '22 at 08:07