10

I am writing my thesis in Lyx and my supervisor has very specific editing requirements. He wants that the chapter number in ToC would be followed by dot, but section numbers not.

Here's code from document class:

\NeedsTeXFormat{LaTeX2e}

\def\@baseclass{report}
\def\@rodzajpracy{magisterska}
\DeclareOption{licencjacka}{\def\@rodzajpracy{licencjacka}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\@baseclass}}
\PassOptionsToClass{a4paper,twoside,openright,12pt}{\@baseclass}
\ProcessOptions

\LoadClass{\@baseclass}


\renewcommand*\@seccntformat[1]{\csname the#1\endcsname\enspace}
\def\numberline#1{\hb@xt@\@tempdima{#1.\hfil}}
\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 \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\mdseries
      \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$}\hfill
      \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}


\endinput
%%
%% End of file `book.cls'.

Working example:

\documentclass[oneside,english]{book}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{babel}
\begin{document}
\tableofcontents{}


\chapter{blabla}


\section{blab blab}


\chapter{bleble}


\section{bleb bleb}
\end{document}

and this is what I get: enter image description here

adding numbers=noenddot in lyx->settings->document class doesn't solve the problem

Marta
  • 157

2 Answers2

7

The package tocloft and its command \cftchapaftersnum provide the possibility to add 'anything' to the chapter number in the toc, i.e. a dot . too.

\documentclass[oneside,english]{book}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{tocloft}%
\usepackage{babel}

\renewcommand{\cftchapaftersnum}{.}%

\begin{document}
\tableofcontents

\chapter{blabla}


\section{blab blab}


\chapter{bleble}


\section{bleb bleb}
\end{document}

enter image description here

6

Remove the line

\def\numberline#1{\hb@xt@\@tempdima{#1.\hfil}}

from the class code and change the definition of \l@chapter as follows:

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

The trick is to do the redefinition of \numberline only locally for chapters.

egreg
  • 1,121,712
  • Thank you very much, this worked without any problems. I'm quite new to LaTeX so I would have never came up with this change. – Marta Aug 26 '14 at 15:20
  • @Marta I'd avoid calling book that class. But maybe you're forced to because of LyX (a tool that I would never use). – egreg Aug 26 '14 at 15:21
  • you are right, I wanted to create my own class with it's own name but I can't get lyx to work with it, so I just decided to replace on of the classes that were available, even though I know it's not the best option at least it works – Marta Sep 03 '14 at 11:16
  • 1
    @egreg How can we add a dot after section numbers in TOC without using additional package like tocloft? – Vahid Damanafshan Aug 13 '19 at 14:58
  • @VahidDamanafshan What's the connection with this answer? – egreg Aug 13 '19 at 15:12
  • 1
    @egreg I'm just curious to know how to add a dot after section numbers in TOC without using additional packages. – Vahid Damanafshan Aug 13 '19 at 15:22