3

I would like to an entry in the Table of Contents with a page number as text "END PAGE". The chapter that is entered in the Table of Contents also is not numbered. I have two errors.

  1. When I explicitly turn off page numbering for this last chapter, with \pagenumbering{empty} I get and error:

    Missing number, treated as zero. ...ine About the Author}{\c@page }{chapter*.7}
    
  2. I would like to have the this last entry in the Table of Contents have a page number of "END PAGE".

MWE:

    \documentclass{MWE}

    \begin{document}

    \frontmatter
    %\begin{dedication}
    \chapter*{Dedication}
    \lipsum[1]
    \chapter*{Acknowledgments}
    \lipsum[1]

    \renewcommand{\listfigurename}{LIST OF FIGURES}
    \renewcommand{\listtablename}{LIST OF TABLES}
    \renewcommand*{\contentsname}{TABLE OF CONTENTS}
    \renewcommand\bibname{REFERENCES}
    \listoftables
    \listoffigures
    \tableofcontents

    \chapter{Abstract}
    \lipsum[1]
    \mainmatter
    \chapter{Let's begin}
    \lipsum[1]  
    \section{First Attempt}
    \lipsum*
    \lipsum[1]

    \bibliographystyle{plain}
    \bibliography{thesis-ref}

    \backmatter
    \chapter{About the Author}
    \pagenumbering{empty} 


    \end{document}

CLASS FILE:

    \NeedsTeXFormat{LaTeX2e}
    \ProvidesClass{MWE}[2017/03/05 My custom class]
    \LoadClass[oneside,12pt]{scrbook}


    \RequirePackage[utf8]{inputenc} % set input encoding (not needed with XeLaTeX)
    \RequirePackage{geometry} % to change the page dimensions
    \geometry{a4paper} % or letterpaper (US) or a5paper or....
    \geometry{margin=1in} % for example, change the margins to 2 inches all round

    \RequirePackage[english]{babel} %set language
    \RequirePackage{blindtext}      %used to generate random text.
    \RequirePackage{lipsum}         %used to generate random text.

    \RequirePackage{graphicx} % support the \includegraphics command and options
    \graphicspath{{figures/}}
    \RequirePackage{scrhack}

    \RequirePackage{amsmath}
    \RequirePackage[algo2e]{algorithm2e}

    \RequirePackage{booktabs} % for much better looking tables
    \RequirePackage{array} % for better arrays (eg matrices) in maths
    \RequirePackage{paralist} % very flexible & customisable lists (eg. enumerate/itemize, etc.)
    \RequirePackage{verbatim} % adds environment for commenting out blocks of text & for better verbatim
    \RequirePackage{subfig} % make it possible to include more than one captioned figure/table in a single float
    % These packages are all incorporated in the memoir class to one degree or another...
    \usepackage{listings}
    \usepackage[english]{babel}

    %%% HEADERS & FOOTERS
    \RequirePackage{fancyhdr} % This should be set AFTER setting up the page geometry
    \pagestyle{fancy} % options: empty , plain , fancy
    \renewcommand{\headrulewidth}{0pt} % customise the layout...
    \lhead{}\chead{}\rhead{}
    \lfoot{}\cfoot{\thepage}\rfoot{}

    %%% SECTION TITLE APPEARANCE
    \RequirePackage{titlesec}
    %Chapter with number headings
    \titleformat{\chapter}[display]
    {\normalfont\centering\bfseries} % format
    {}  % label none here
    {0pt}% sep
    {\MakeUppercase{\chaptertitlename} \thechapter: \uppercase} % before-code
    []% after-code
    %Format the numberless chapter headings.
    \titleformat{name=\chapter, numberless}[display]{\normalfont\centering\bfseries}{}{0pt}{\uppercase}[]
    \titleformat{\section}{\normalfont}{}{0pt}{}[]
    \titleformat{\subsection}{\normalfont}{}{0pt}{}[]
    \titleformat{\subsubsection}{\normalfont}{}{0pt}{}[]
    \titleformat{\paragraph}{\normalfont}{}{0pt}{}[]
    \titleformat{\subparagraph}{\normalfont}{}{0pt}{}[]


    %%% ToC (table of contents) APPEARANCE
    \RequirePackage[nottoc]{tocbibind} % Put the bibliography in the ToC
    \RequirePackage[titles,subfigure]{tocloft} % Alter the style of the Table of Contents


    \renewcommand{\cfttoctitlefont}{\bfseries}
    \renewcommand{\cftchapfont}{\rmfamily\mdseries\upshape}
    \renewcommand{\cftchapdotsep}{\cftnodots}
    \renewcommand{\cftchappagefont}{\rmfamily\mdseries\upshape}
    \renewcommand{\cftsecfont}{\rmfamily\mdseries\upshape}
    \renewcommand{\cftsecdotsep}{\cftnodots}
    \renewcommand{\cftsecpagefont}{\rmfamily\mdseries\upshape} % No bold!
    \renewcommand{\cftsubsecdotsep}{\cftnodots}
    \renewcommand{\cftsubsubsecdotsep}{\cftnodots}
    \renewcommand{\cftfigdotsep}{\cftnodots}
    \renewcommand{\cftfigfont}{Figure }
    \renewcommand{\cfttabdotsep}{\cftnodots}
    \renewcommand{\cfttabfont}{Table }

    \RequirePackage{hyperref} %I would like to be able to jump around the pdf
    \RequirePackage{setspace}
    \RequirePackage{indentfirst}%Indent the first paragraph of every chapter.

    %Ensure all chapter entries in the table of contents are upper case.
    \RequirePackage{textcase}
    \makeatletter
    \let\oldcontentsline\contentsline
    \def\contentsline#1#2{%
        \expandafter\ifx\csname l@#1\endcsname\l@chapter
        \expandafter\@firstoftwo
        \else
        \expandafter\@secondoftwo
        \fi
        {%
            \oldcontentsline{#1}{\MakeTextUppercase{#2}}%
        }{%Do nothing
            \oldcontentsline{#1}{#2}%
        }%
    }
    \makeatother

EDIT: I have changed paradigms to not use a class file and have adopted the solution given by esdd with the new KOMA script.

  • 1
    Welcome! Don't use \makeatletter or \makeatother in .cls or .sty files. hyperref should generally be loaded last, with certain specific exceptions. Do you really need lipsum and blindtext in the class? Is the class used only for creating MWEs? I guess you know that you are breaking a bunch of KOMA's functionality by the packages you're using. (It isn't necessarily wrong to do this if you have to do it.) – cfr Apr 28 '17 at 3:30
  • Are you looking for \pagenumbering{gobble}? – cfr Apr 28 '17 at 3:32
  • I did end up using the \pagenumbering{gobble} command. Thank you for the suggestion. – Joshua Winfrey May 6 '17 at 1:03
3

With your class

\newcommand\EndPageInToC{%
  \addtocontents{toc}{\protect\renewcommand{\protect\cftchappagefont}{END PAGE\protect\nullfont}}%
  \renewcommand{\chapterpagestyle}{empty}%
}

in the preamble and then

\backmatter
\EndPageInToC
\chapter{About the Author}
\lipsum[1]

results in

enter image description here

Why the sections are numbered in ToC, but not in the document?


Here is an additional suggestion without titlesec, tocloft and tocbibind, but it needs an uptodate KOMA-Script version.

\documentclass[
  oneside,
  12pt,
  numbers=noenddot,
  listof=entryprefix,
  listof=totoc,
  bibliography=totoc,
  index=totoc
]{scrbook}[2017/01/03]

\usepackage[utf8]{inputenc}
\usepackage{geometry}
\geometry{margin=1in}

\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{lipsum}

\usepackage{graphicx}
\graphicspath{{figures/}}
\usepackage{scrhack}

\usepackage{amsmath}
\usepackage[algo2e]{algorithm2e}

\usepackage{booktabs}
\usepackage{array}
\usepackage{paralist} % maybe better: enumitem
\usepackage{verbatim}
\usepackage{subfig} % better: subcaption
\usepackage{listings}

\usepackage[automark]{scrlayer-scrpage}
\clearpairofpagestyles
\cfoot*{\pagemark}

\RedeclareSectionCommand[
  beforeskip=-5.4\baselineskip plus -\parskip,
  innerskip=0pt,
  afterskip=2.725\baselineskip plus .115\baselineskip minus .192\baselineskip,
  font=\normalfont\bfseries
]{chapter}
\renewcommand\raggedchapter{\centering}
\renewcommand\chapterformat{\MakeUppercase{\chaptername} \thechapter:\ }
\renewcommand\chapterlinesformat[3]{#2\MakeUppercase{#3}}
\usepackage{xpatch}
\xpatchcmd{\addchaptertocentry}
  {\addtocentrydefault{chapter}{#1}{#2}}
  {\addtocentrydefault{chapter}{#1}{\protect\chaptertocentryformat{#2}}}
  {}{\PatchFailed}
\newcommand\chaptertocentryformat[1]{#1}
\AfterTOCHead[toc]{\renewcommand\chaptertocentryformat[1]{\MakeUppercase{#1}}}
\addtokomafont{chapterentry}{\normalfont}

\newcommand\EndPageInToC{%
  \addtocontents{toc}{\RedeclareSectionCommand[tocpagenumberbox=\protect\EndPageBox]{chapter}}%
  \renewcommand\chapterpagestyle{empty}%
}
\newcommand\EndPageBox[1]{\makebox{END PAGE}}

\RedeclareSectionCommands[
  font=\normalfont,
  toclinefill=\hfill
]{section,subsection,subsubsection,paragraph,subparagraph}
\renewcommand\sectionlinesformat[4]{#4}
\renewcommand\sectioncatchphraseformat[4]{#4}

\DeclareTOCStyleEntry[
  linefill=\hfill
]{tocline}{figure}
\DeclareTOCStyleEntry[
  linefill=\hfill
]{tocline}{table}

\usepackage{indentfirst}
\usepackage{setspace}
\usepackage{hyperref}

\renewcaptionname{english}{\contentsname}{Table of Contents}
\renewcaptionname{english}{\bibname}{References}
\begin{document}

\frontmatter
\addchap*{Dedication}
\lipsum[1]
\addchap*{Acknowledgments}
\lipsum[1]

\listoftables
\listoffigures
\tableofcontents

\chapter{Abstract}
\lipsum[1]
\mainmatter
\chapter{Let's begin}
\lipsum[1]  
\section{First Attempt}
\lipsum*
\lipsum[1]

\bibliographystyle{plain}
\bibliography{thesis-ref}

\backmatter
\EndPageInToC
\chapter{About the Author}
\lipsum[1]

\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.