0

I have next code for defining dots after chapter title in TOC:

\newcommand\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%8em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode 
      \advance\leftskip\@tempdima
      \hskip -\leftskip
{#1}\unskip\nobreak\leaders\hbox{$\m@th \mkern \@dotsep mu.\mkern \@dotsep mu$}\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par      
      \penalty\@highpenalty
      \endgroup
  \fi}

An result is: enter image description here

How can I get rid of dots behind chapter title? Thanks.

UPDATE

I found that if I put some static text before {#1} in the code above - dots respect the size of static text and start after it. I am not sure how latex (overleaf) calculates {#1} at this point. It seems that it renders dots first and then renders the content of given parameter #1. Do you have any idea how I can delay rendering of dots in the code above after content of #1 is ready? Or is it possible to "force" rendering of content? I would appreciate if you give me some background how latex does the rentering (in what stages or accroding to definitions in the file).

Here is another excerpt of how chpaters appear in the ToC:


\newcommand\@chapapp{Chapter}
\newcommand\chapter{%
  \clearpage
  \doublespacing
  \thispagestyle{myotherheadings}
  \global\@topnum\z@
  %\@afterindentfalse
  \@afterindenttrue
  \secdef\@chapter\@schapter}
\def\@chapter[#1]#2{%
  \refstepcounter{chapter}%
  \typeout{\@chapapp\space\thechapter. #1}%
  % 1999.6 Period after chapter number removed in TOC.  HJG
  \addcontentsline{toc}{chapter}{\protect\numberline{%
        {\@chapapp\space\thechapter:\space#1}}}%
  \chaptermark{#1}%
  \@makechapterhead{#2}%
  \@afterheading
}

\chapter is redefined and contains \addcontentsline - with last parameter {\protect\numberline{{@chapapp\space\thechapter:\space#1}}} which defines the content of ToC line - which is {#1} in the first excerpt. @makechapterhead forms the chapter title itself (code is ommited)

  • 1
    Welcome! It is always hard to debug code fragments. Try removing the dot in mu.\mkern. If that does not help, consider posting a complete document that starts with \documentclass, ends with \end{document}, can be compiled and illustrates the issue. – Schrödinger's cat Nov 6 '19 at 2:07
  • Your code snippet doesn't have anything to do with adding a dot. You'll have to supply us with more supporting evidence that can replicate the problem before we can help you. – Werner Nov 6 '19 at 2:27
  • @Schrödinger'scat hi, removing dot - removes all dots from chapter line - but I need them. About document class - it is based on custom class (cls file): \documentclass[12pt,frontmatter,copyright,thesis]{usfmanus} – dvitel Nov 6 '19 at 2:42
  • The class file is big enough (do not want to post it all) - I am not sure what other related setting could be involved in the dotted line config for chapter (if you suggest what part I need to post I can do this) - it seems that the lengths of #1 (in code above) is not taken into account - and hbox fill uses space of #1 - can I somehow manually specify offset for hbox of dots? I am a newbie in latex – dvitel Nov 6 '19 at 2:53
  • Well, I can only make qualified statements if I have a code to play with. Either the above fragment is responsible for the dots and can be embedded in a small but complete toy document, or not. If yes, please provide such a toy document, if not, what do you suggest? – Schrödinger's cat Nov 6 '19 at 3:09
0

Why not use the tocloft package (> texdoc tocloft) which handles many aspects of the appearance of the ToC, etc.?

With a normal \caption command:

\documentclass{report}
\usepackage{tocloft}
\renewcommand{\cftchapdotsep}{\cftdotsep}
\begin{document}
\tableofcontents
\chapter{One}
\end{document}

The above will produce dots after a chapter entry in the ToC.

  • Hi, Peter. Unfortunatelly I cannot (or do not want to) use tocloft: 1) just including package + renewcommand in main.tex file renders same dots behind text 2) i do not want to totally rewrite the project - dump the cls file and define title page toc, figures and everything in main.tex - though it will work - it will be much effort and I can ruin other styling – dvitel Nov 14 '19 at 18:23
0

Seems that I found the solution. As I mentioned in update - problem was with how #1 is rendered - it was rendered after rendering of the dots - it was due to \numberline inside \addcontentsline of the code from update above.

After removing numberline - dots are rendered as necessary - but I had to fix some vspacing for some entries in ToC

enter image description here

  • You show a result but not the code that produced it. Doesn't seem like an answer to me/. – Peter Wilson Nov 15 '19 at 20:00

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.