I'm trying to format my dissertation, and the formatting guidelines require a dotted line for chapters as well as sections, etc. The challenge is that I have several appendices, and the length of the word "Chapter" is less than the length of the word "Appendix", which is causing issues with getting the spacing. The .cls style was provided to me by another student and appears incompatible with tocloft, so that is not a working solution for me. I can reproduce the problem using the book package by redefining \chapter and \l@chapter accordingly, so the fix is somewhere in these two definitions.
MWE1
In this MWE, I've changed the definition of \l@chapter is redefined to add the dotted lines, using How to add leaders to Table of Contents without tocloft? as a guide. Notice however, that the spacing of between "Appendix A" and the title is too small. (This isn't strictly a dotted line issue, I'd have to solve it anyways, but (as I will show), they compound.
\documentclass{book}
\makeatletter
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{plain}%
\global\@topnum\z@
\@afterindentfalse
\secdef\@chapter\@schapter}
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
\addcontentsline{toc}{chapter}%
{\protect\numberline{\@chapapp\hspace{2mm}\thechapter}\hspace{1.5cm}{#1}}%
\else
% \addcontentsline{toc}{chapter}{\MakeTextUppercase{#1}}%
\addcontentsline{toc}{chapter}{{#1}}%
\fi
\chaptermark{#1}%
\addtocontents{lof}{\protect\addvspace{0\p@}}%
\addtocontents{lot}{\protect\addvspace{0\p@}}%
\if@twocolumn
\@topnewpage[\@makechapterhead{#2}]%
\else
\@makechapterhead{#2}%
\@afterheading
\fi}
\renewcommand*\l@chapter[2]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \normalfont
\advance\leftskip\@tempdima
\hskip -\leftskip
#1\nobreak
\leaders\hbox{$\m@th
\mkern \@dotsep mu\hbox{.}\mkern \@dotsep
mu$}\hfill%
\nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\penalty\@highpenalty
\endgroup
\fi}
\makeatother
\begin{document}
\tableofcontents
\chapter{one longer title}
\chapter{two}
\chapter{three}
\appendix
\chapter{This needs to be right too}
\end{document}
MWE2
It looked like the issue was that the space from the start of the line to the text start was hard-coded, so I removed that, and moved more of the content inside the \numberline command.
(Aside - I cannot find any documentation for what \numberline does, anyone know?)
This basically shifts the spacing problem to the dots instead of the text - so I next tried doing the opposite, and removed everything from inside \numberline - and it's almost right, but now there is an indent that will not go away.
(N.B. - if anyone does not need dots, change {\protect\numberline{}\@chapapp\hspace{2mm}\thechapter\hspace{2mm}{#1}}% to {\protect\numberline{\@chapapp\hspace{2mm}\thechapter\hspace{2mm}{#1}}}% solved the spacing problem.
I've tried the normal hack of adding \hspace{-.25in}, and that does not work.
I do not see where this indent is defined.
Can anyone help?
\documentclass{book}
\makeatletter
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{plain}%
\global\@topnum\z@
\@afterindentfalse
\secdef\@chapter\@schapter}
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
\addcontentsline{toc}{chapter}%
{\protect\numberline{}\@chapapp\hspace{2mm}\thechapter\hspace{2mm}{#1}}%
\else
% \addcontentsline{toc}{chapter}{\MakeTextUppercase{#1}}%
\addcontentsline{toc}{chapter}{{#1}}%
\fi
\chaptermark{#1}%
\addtocontents{lof}{\protect\addvspace{0\p@}}%
\addtocontents{lot}{\protect\addvspace{0\p@}}%
\if@twocolumn
\@topnewpage[\@makechapterhead{#2}]%
\else
\@makechapterhead{#2}%
\@afterheading
\fi}
\renewcommand*\l@chapter[2]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \normalfont
\advance\leftskip\@tempdima
\hskip -\leftskip
#1\nobreak
\leaders\hbox{$\m@th
\mkern \@dotsep mu\hbox{.}\mkern \@dotsep
mu$}\hfill%
\nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\penalty\@highpenalty
\endgroup
\fi}
\makeatother
\begin{document}
\tableofcontents
\chapter{one longer title}
\chapter{two}
\chapter{three}
\appendix
\chapter{This needs to be right too}
\end{document}



