0

In the book class, I want parts, chapters, sections, and subsections numbers to be followed by a dot, both in headings and TOC, with one exception: chapter numbers should only add a dot in TOC, but not in headings.

This may seem a bit whimsical and strange, but the cause is that in my book design the chapter numbers go inside a box, so it is not appropriate to put the point.

The following screenshots show a fragment of a chapter heading and a TOC fragment, respectively:

enter image description here

enter image description here

I used this code for the control of dots:

% Section style definition
\titleformat{\section}[runin]
{\normalsize \bfseries}
{\color{black} \S \thesection}
{1ex}{\color{black}}[\quad]

% Subsection style definition
\titleformat{\subsection}[runin]
{\normalsize \bfseries}
{\color{black} \S \thesubsection}
{1ex}{\color{black}}[\quad]

\renewcommand\thepart{\Roman{part}.}
\renewcommand\thesection{\thechapter.\arabic{section}.}
\renewcommand\thesubsection{\thesection\arabic{subsection}.}

As can be seen in the second screenshot, in TOC the chapter number is not followed by a dot, and this is the problem I want to solve.

EDIT 1 _________________________________________________________________

I had avoided including all the code in the preamble as it was quite cumbersome. However, some people who want to help me advise me to include a compilable version, which I reproduce omitting many definitions of my own, but showing all the loaded packages because sometimes the problems arise due to incompatibilities between packages:

\documentclass[a4paper,14pt,twoside,reqno]{extbook}
\usepackage[tmargin=28mm,bmargin=28mm,lmargin=28mm,rmargin=28mm]{geometry}
\usepackage{amsmath, amsfonts,amssymb,amstext,amsthm,mathpazo, xfp, latexsym}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{cite}
\usepackage{times}
\usepackage[usenames]{color}
\usepackage[dvipsnames]{xcolor}
\usepackage{pstricks}
\usepackage{tikz, ifthen, bclogo}
\usepackage{pst-poly}
\usepackage{pst-all}
\usetikzlibrary{decorations.fractals,calc}
\usetikzlibrary{arrows,calc,patterns,shadows,petri,decorations.markings,shapes,trees}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{lindenmayersystems}
\usepackage{latexsym, graphicx}
\usepackage{subfigure}
\usepackage[thicklines, makeroom]{cancel}
\usepackage{verbatim}
\usepackage{wasysym}
\usepackage{stmaryrd, scalerel, stackengine}
\usepackage{pifont}
\usepackage{calligra}
\usepackage{mathtools}
\usepackage{titlesec}
\usepackage{underoverlap}
\usepackage{theorem}
\usepackage{secdot}

% Definition of bcancelto _____________________________________
    \usepackage{etoolbox}
    \makeatletter
    %patch \canto@vector to correctly place script.
    \pretocmd{\canto@vector}{\edef\testneg{#4<0}}{}{\@latex@error{Patch fail}}
    \patchcmd{\canto@vector}{^}{\ifnum\testneg_\else^\fi}{}{\@latex@error{Patch fail}}
    \patchcmd{\canto@vector}{\raise#2\dimen@}{\raise\dimexpr\ifnum\testneg-\ht\z@+\fi#2\dimen@}{}{\@latex@error{Patch fail}}
    
    \renewcommand*{\thepage}{{\small} \arabic{page}} % Resize page numbers
     
    % _____________________________________________
      
    \↨DeclareMathAlphabet{\mathpzc}{OT1}{pzc}{m}{it}
    
    % Frame definition: space to edge and edge thickness:
    \fboxsep 6pt \fboxrule 1pt

    % Section style definition
    \titleformat{\section}[runin]
    {\normalsize \bfseries}
    {\color{black} \S \thesection}
    {1ex}{\color{black}}[\quad]
    
    % Subsection style definition
    \titleformat{\subsection}[runin]
    {\normalsize \bfseries}
    {\color{black} \S \thesubsection}
    {1ex}{\color{black}}[\quad]
    
    \renewcommand\thepart{\Roman{part}.}
    \renewcommand\thesection{\thechapter.\arabic{section}.}
    \renewcommand\thesubsection{\thesection\arabic{subsection}.}
    
    %TOC edit attempt:
    %\let\OldNumberline=\numberline
    %\RenewDocumentCommand{\numberline}{ m }{%
    %   \OldNumberline{#1.}%
    %}
    
    \date{} % clear date
        
    % Frame definition: margins and border thickness:
    \fboxsep 6pt \fboxrule 1pt
    
    \raggedbottom % For LaTeX to leave excess space at the bottom of the sheet and not distribute white spaces across it.
    
    \setlength\parindent{0pt} % noindent in the whole document
    
    \titlespacing*{\section}{0pt}{3ex}{2ex} %Espacio a la izquierda, espacio antes del título, espacio después del título.
    
    \titlespacing*{\subsection}{0pt}{3ex}{2ex}
    
    \usepackage[colorlinks=true,linkcolor=black]{hyperref}
    
    \titleformat{\chapter}{\large \bfseries}{\filright \fboxrule 3pt \framebox[1.8em][c]{\thechapter}}{16pt}{\large}   
    
%___________________________________________________________________________
        
       
    \setcounter{secnumdepth}{3}
    \setcounter{tocdepth}{3}
    \setcounter{chapter}{0}
    \thispagestyle{empty} 
    \renewcommand{\baselinestretch}{1.25} % line spacing
    
    % head and foot __________________________________________
    \usepackage{emptypage} %To skip header / footer on empty pages (generated so that each chapter starts on an odd page)
   
    \begin{document}
        \pagestyle{plain}
        \tableofcontents
            
        \addcontentsline{toc}{chapter}{FOREWORD.}
        \chapter*{FOREWORD.}
    \end{document}

EDIT 2 _________________________________________________________________

With this code,

    \usepackage{tocloft}
\renewcommand{\cftchapaftersnum}{.}

I get the following error:

enter image description here

The strangest thing about these error messages is that line 623 only contains text and line 624 is blank.

EDIT 3 _________________________________________________________________

In the TOC, the space after the subsection number and the subsection title is greater than between number and section title, how to get these spaces are equal?. See this screenshot?:

enter image description here

4
  • 1
    Your code is too incomplete to be compiled and to experiment with it. I would suggest: try to redefine your chapter titles after \tableofcontents. Besides: for me it looks weird having a different lay-out of titles in the book itself and in the TOC. Why do you not just take the same lay-out in the TOC? It facilitates the orientation of the reader.
    – C. Peters
    Jun 14, 2021 at 6:50
  • Thank you, C. Peters. Yes, you are right, but, in the TOC, could the chapter number go inside a box just like in the header? This may seem a bit whimsical, but I'm just trying to get a custom design. It seems to me that it clarifies the reading. Jun 14, 2021 at 12:06
  • 1
    \usepackage{tocloft,etoolbox} offers a lot of possibilities. Try how far you can get with your definition \renewcommand\cftchapfont{your choices}. According to the manual "This controls the appearance of the title (and its preceding number, if any)."
    – C. Peters
    Jun 14, 2021 at 12:43
  • 1
    When I compile your file with {tocloft,etoolbox}, I also get error messages regarding the list of tables and the list of figures, but that is caused by the lack of tables and figures. You just can ignore the messages. Besides, I somehow managed to insert the box in the Table of contents, but not properly and I got a lot of error messages for the titles in the document itself. So, my conclusion is that it is possible to copy the lay-out of the text in the top, but I am not good enough in LaTeX to figure out how.
    – C. Peters
    Jun 15, 2021 at 6:40

2 Answers 2

1

By playing quite a bit, I got this:

      \renewcommand\cftchapnumwidth{2em}
\renewcommand\cftsecindent{2em}
\renewcommand\cftchapaftersnum{\hskip-1.4em
\filright \fboxrule 3pt \fbox{$\mathstrut${\Large~~~}}}%[1.8em][c]{}}
\renewcommand\cftsecpresnum{\S}

inserted after \titleformat and \usepackage{tocloft,etoolbox} You have to ignore the messages regarding lof and lot. The result is: Table of Contents

I had to adjust the numwidth for the chapter and the indent for the section. Besides, it is not logical to use a paragraph symbol for the sections as well as for the subsections. Just one of them can be a paragraph.

9
  • Great, Peter! Just 12 hours ago you were saying, "but I'm not good enough at LaTeX to figure out how." Well, it seems like you're good enough at LaTeX. Thank you very much for your effort and dedication to a problem that arises from a simple stylistic whim and that has interested few; however, I believe that, at least, it has didactic value to learn LaTeX. Kind regards from Spain. Jun 15, 2021 at 22:27
  • One last question, C. Peters: how can you control the space between the number and the title? To clarify the question I include a screenshot in the EDIT 3 of my question, in which you can see that the space after the subsection number and the subsection title is greater than between number and section title, how to get these spaces are equal?. Jun 15, 2021 at 23:18
  • 1
    The box numwidth is aligned left, to guarantee alignment of the beginning of the numbers. When you add more than nine sections with at least one subsection or 10 subsections, the gap will diminish. When you have a lot of sections, you will have to enlarge the \cftsecnumwidth as well, otherwise your section numbers will mix up with the title of the section. If you are sure that you do not exceed three digits in total (for the subsections), you can tighten numwidth with \renewcommand\cftsubsecnumwidth{2.5em}, which in my file is the closest I can get to the gap for the section.
    – C. Peters
    Jun 16, 2021 at 6:43
  • 1
    I like puzzling, so I tried and reread the indeed not easy to understand tocloft manual. In line 19 you added the subfigure package. When you remove it, the two 'depth'-errors do not appear anymore, and I get the same result for the toc. I do not use the package for my thesis, while I have a lot, so it seems somehow superfluous.
    – C. Peters
    Jun 16, 2021 at 11:00
  • 1
    You are welcome!
    – C. Peters
    Jun 16, 2021 at 12:41
1

Use the tocloft package. The following is a condensed version of your MWE that contains the essentials of your code related to your problem, plus the tocloft solution.

% dotprob.tex  SE 601137

\documentclass[a4paper,14pt,twoside,reqno]{extbook}
\usepackage[tmargin=28mm,bmargin=28mm,lmargin=28mm,rmargin=28mm]{geometry}

\usepackage{tocloft}
\renewcommand{\cftchapaftersnum}{.}

\usepackage{titlesec}

    \titleformat{\chapter}{\large \bfseries}{\filright \fboxrule 3pt \framebox[1.8em][c]{\thechapter}}{16pt}{\large}   
   
    \begin{document}
        \pagestyle{plain}
        \tableofcontents
            
        \addcontentsline{toc}{chapter}{FOREWORD.}
        \chapter*{FOREWORD.}
\chapter{Regular}

    \end{document}

enter image description here

You must log in to answer this question.

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