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

2 Answers 2

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.

6
  • 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, 2014 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, 2014 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 3, 2014 at 11:16
  • 1
    @egreg How can we add a dot after section numbers in TOC without using additional package like tocloft? Aug 13, 2019 at 14:58
  • 1
    @egreg I'm just curious to know how to add a dot after section numbers in TOC without using additional packages. Aug 13, 2019 at 15:22
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

2
  • 1
    This solution, with this one too, is really useful! Thanks!
    – user101590
    Mar 27, 2017 at 9:59
  • 2
    This is for sections numbering \renewcommand{\cftsecaftersnum}{.}% . Thank you for your useful answer.
    – F 505
    Apr 26, 2017 at 9:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .