0

Here is my document from the beginning:

\documentclass{book}
\usepackage[utf8]{inputenc}

\usepackage[a4paper, margin=1in]{geometry}

\usepackage{amsmath,amsfonts,amssymb}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{lipsum}
\usepackage{tocloft}

\usepackage{titlesec}

\begin{document}
   
    \newgeometry{top=1.75in,hmargin=1in, bottom=1in} 
    
    \pagenumbering{gobble}

And here is the part that when I added to the document the numbering of the pages changed from the footer to the header (left and right alternatively):

\titleformat{\chapter}[display]
  {\normalfont\LARGE\bfseries}
  {\titleline{}\vspace{5pt}\titleline{}\vspace{1pt}%
  \MakeUppercase{\chaptertitlename} \thechapter}
  {1pc}
  {\titleline{}\vspace{0.5pc}}



\chapter{BIOLOGICAL STRUCTURE}

The main results of this chapter is to give 
\section{PRELIMINARIES}

I also wanted to say that I used to use documentclass{article} when my numbering was in the footer.

Can anyone tell me please what changed the place of the page numbering? and how can I keep the documentclass{book} and keep the page numbers in the footer?

8
  • It wasn't the use of \titleformat that changed the location. It was changing from \documentclass{article} to \documentclass{book} that changed the location of the page numbers. However, if you're using \pagenumbering{gobble}, there should be no page numbers.
    – Werner
    Jun 24, 2021 at 21:04
  • Yeah some pages I do not want them to contain numbers @Werner ...... but how can I keep the page number in the footer while also using the documentclass{book} do you have any suggestions for that?
    – Happy
    Jun 25, 2021 at 1:35
  • 5
    Does this answer your question? Page numbering, book class
    – SolidMark
    Jun 25, 2021 at 7:23
  • 1
    you just replace fancyhead with fancyfoot for the page numbers.
    – SolidMark
    Jun 25, 2021 at 12:51
  • 1
    You might also look at the \frontmatter and \mainmatter commands for book class. Jun 25, 2021 at 13:43

2 Answers 2

1

This shows how to do it without fancyhdr.

\documentclass{book}
\usepackage[utf8]{inputenc}

\usepackage[a4paper, margin=1in]{geometry}

\usepackage{amsmath,amsfonts,amssymb}
\usepackage{graphicx}
\usepackage{setspace}% avoid if possible
\usepackage{lipsum}

\usepackage{tocloft}
\usepackage{titlesec}
\titleformat{\chapter}[display]
  {\normalfont\LARGE\bfseries}
  {\titleline{}\vspace{5pt}\titleline{}\vspace{1pt}%
  \MakeUppercase{\chaptertitlename} \thechapter}
  {1pc}
  {\titleline{}\vspace{0.5pc}}

\makeatletter
\def\ps@headings{%
      \def\@oddfoot{\normalfont\hfil\thepage\hfil}%
      \def\@evenfoot{\normalfont\hfil\thepage\hfil}}
      \def\@evenhead{\hfil\slshape\leftmark}%
      \def\@oddhead{{\slshape\rightmark}\hfil%
      \let\@mkboth\markboth
    \def\chaptermark##1{%
      \markboth {\MakeUppercase{%
        \ifnum \c@secnumdepth >\m@ne
          \if@mainmatter
            \@chapapp\ \thechapter. \ %
          \fi
        \fi
        ##1}}{}}%
    \def\sectionmark##1{%
      \markright {\MakeUppercase{%
        \ifnum \c@secnumdepth >\z@
          \thesection. \ %
        \fi
        ##1}}}}
\makeatother
\pagestyle{headings}% apply new definitions
  
\usepackage{lipsum}% random text

\begin{document}
\frontmatter
\begin{titlepage}
\vspace*{0.75in}% assuming one page only
Note that \verb|\maketitle| is optional.
\end{titlepage}
\tableofcontents

\mainmatter
\chapter{Title}
\lipsum[1-20]

\end{document}
0
1

And this shows how to do with fancyhdr. (It can be frustrating some times to use this, so beware!). You control how the page numbers are displayed in the odd and even pages using the options L and R for left side and right side and O and E for odd and even pages. Keep in mind that, usually odd pages are to the right and even pages are to the left of a book. So the options RO, LE were passed to the fancyfoot. Also by default, the page number at the beginning of a chapter is in the center of the footer. To change that, you must redefine the plain page style. So the full code is:

\documentclass[10pt, twoside]{book}

%\usepackage[utf8]{inputenc} % Usually you don't need it. So I commented this out.

\usepackage[a4paper, margin=1in]{geometry}

\usepackage{amsmath,amsfonts,amssymb}
\usepackage{graphicx}
\usepackage{setspace} % John Kormylo suggests you avoid this if possible.
\usepackage{lipsum}
\usepackage[titles]{tocloft}

\usepackage{titlesec}
 \titleformat{\chapter}[display]
  {\normalfont\LARGE\bfseries}
  {\titleline{}\vspace{5pt}\titleline{}\vspace{1pt}%
  \MakeUppercase{\chaptertitlename} \thechapter}
  {1pc}
  {\titleline{}\vspace{0.5pc}}
  
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\fancyfoot[RE, LO]{\thepage}

\begin{document}

\frontmatter

\chapter{Preface}
\lipsum[1-2]

\tableofcontents

\mainmatter
\chapter{Chap 1}
\section{Sec 1}
\lipsum[3-30]
\chapter{Chap 1}
\section{Sec 1}
\lipsum[4]

\backmatter
\lipsum[7-8]
\end{document}

The beginning of a chapter would have its page numbered in the center of the footer like this:

Beginning of a chapter

In case you want to make page numbers appear everywhere as usual then you can add additional commands just after fancyhdr definitions:

\fancypagestyle{plain}{
\fancyhf{}
\fancyfoot[LE,RO]{\thepage}}

The next few pages of a chapter shall look like this:

Next page of chapter

Lastly, if you don't want page numbers to show up in some pages then you can use \thispagestyle{empty} followed by a \clearpage command where you want the page to end and begin another page.

Not the answer you're looking for? Browse other questions tagged .