-1

I want to insert the page number as seen here:

enter image description here

that changes in accordance with the chapter (the pages of the chapter have all page numbers inserted in the same position, whereas for the subsequent chapter, they are inserted a bit below the first position). I don't know if I am clear enough.

Ingmar
  • 6,690
  • 5
  • 26
  • 47

1 Answers1

2

Here an example using KOMA-Script package scrlayer-scrpage:

\documentclass{book}
\usepackage[automark,pagestyleset=KOMA-Script,headsepline]{scrlayer-scrpage}

\newlength{\outermarkoffset} \setlength{\outermarkoffset}{\dimexpr 1in+\topmargin+\headheight+\headsep\relax} \DeclareNewLayer[% background, oddpage, outermargin, addvoffset=\dimexpr \outermarkoffset+\baselineskip\value{chapter}2\relax, contents={% \raggedleft\pagemark\hspace*{1em}\par }, ]{oddpagenumber}

\DeclareNewLayer[% background, evenpage, outermargin, addvoffset=\dimexpr \outermarkoffset+\baselineskip\value{chapter}2\relax, contents={% \raggedright\hspace*{1em}\pagemark\par }, ]{evenpagenumber}

\AddLayersToPageStyle{scrheadings}{oddpagenumber,evenpagenumber} \AddLayersToPageStyle{plain.scrheadings}{oddpagenumber,evenpagenumber}

\AddToHook{cmd/appendix/before}{% \cleardoublepage \addtolength{\outermarkoffset}{\dimexpr\baselineskip\value{chapter}2\relax}% }

\usepackage{mwe}

\begin{document} \tableofcontents \blinddocument \blinddocument \blinddocument \blinddocument \blinddocument \blinddocument \appendix \blinddocument \end{document}

If you are already using package fancyhdr, you can use scrlayer-fancyhdr instead:

\documentclass{book}
\usepackage{scrlayer-fancyhdr}
\pagestyle{fancy}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \fancyfoot[C]{\pagemark}%
  \renewcommand*{\headrulewidth}{0pt}%
}

\newlength{\outermarkoffset} \setlength{\outermarkoffset}{\dimexpr 1in+\topmargin+\headheight+\headsep\relax} \DeclareNewLayer[% background, oddpage, outermargin, addvoffset=\dimexpr \outermarkoffset+\baselineskip\value{chapter}2\relax, contents={% \raggedleft\pagemark\hspace*{1em}\par }, ]{oddpagenumber}

\DeclareNewLayer[% background, evenpage, outermargin, addvoffset=\dimexpr \outermarkoffset+\baselineskip\value{chapter}2\relax, contents={% \raggedright\hspace*{1em}\pagemark\par }, ]{evenpagenumber}

\AddLayersToPageStyle{@everystyle@}{oddpagenumber,evenpagenumber}

\AddToHook{cmd/appendix/before}{% \cleardoublepage \addtolength{\outermarkoffset}{\dimexpr\baselineskip\value{chapter}2\relax}% }

\usepackage{mwe}

\begin{document} \tableofcontents \blinddocument \blinddocument \blinddocument \blinddocument \blinddocument \blinddocument \appendix \blinddocument \end{document}

two pages of different chapters

For more information about scrlayer-fancyhdr see the manual of that package.

For more information about \DeclareNewLayer and \AddLayersToPageStyle see the KOMA-Script manuals.

For more information about \AddToHook see lthooks-doc.pdf, which is part of every LaTeX distribution.

cabohah
  • 11,455
  • Thank you for your response, however when using the second proposed script I get to page numbering. I only want one and I want it in a drawn space (will eventually want it to be colored in black and the number in white) – Wallflower Apr 05 '23 at 11:25
  • @Wallflower Your example image also has two page numbers (one in the outer margin and one in the footline). However, you can easily remove the number in the footer, e.g., using \fancyfoot[C]{}. Color was also not part of the question, but is simple using package xcolor and e.g., \colorbox and \color. Please ask a new question with more details. – cabohah Apr 05 '23 at 13:11
  • I cannot use the \fancyfoot command since I am using the MastersDoctoralThesis template for my report :( – Wallflower Apr 25 '23 at 12:16
  • 1
    @Wallflower How should I know this from your image and insufficient description in your question? This is why you should always add a minimal working example to your questions. But AFAIK MasterDoctoralThesis already uses scrlayer-scrpage. So you can use all the nice macros of that package to add an remove fields, e.g., \cfoot[]{}. Please read the manual. – cabohah Apr 25 '23 at 12:36
  • I posted a new question as previously requested here https://tex.stackexchange.com/questions/683772/creative-page-numbering-without-using-fancyhdr?noredirect=1#comment1696540_683772. Sorry for the inconvenience... – Wallflower Apr 25 '23 at 12:38
  • 1
    @Wallflower Questions should basically stand for themselves. Helpers cannot be expected to go through all of a questioner's questions and check them for relevance. Questions that stand for themselves are also beneficial for other help seekers. – cabohah Apr 25 '23 at 12:48
  • Understood, thank you! – Wallflower Apr 25 '23 at 12:52