0

I want to add a dot after sections and subsections numbers, even in the table of contents and cross-references. With \sectiondot{subsection} of secdot package we don't get the final dot in table of contents and cross-references.

I have tried by redefining the following commands:

\renewcommand{\thechapter}{\arabic{chapter}.}
\renewcommand{\thesection}{\thechapter\arabic{section}.}
\renewcommand{\thesubsection}{\thechapter\thesection\arabic{subsection}.}

But the result in the table of contents is the following: enter image description here

That is, the subsections appear numbered as if they were subsubsections.

And the subsections headings shows as follows: enter image description here

EDIT 1 _______________________________________________________________

With this code of Dr. Manuel Kuehner,

\renewcommand\thechapter{\arabic{chapter}.}
\renewcommand\thesection{\thechapter\arabic{section}.}
\renewcommand\thesubsection{\thesection\arabic{subsection}.}

the result is correct in the table of contents but in the headings of sections and subsections we get this:

enter image description here

EDIT 2 _______________________________________________________________

Furthermore, I wish the chapter numbers do not end by a dot, as they will go inside a box, as it is shown in this image:

enter image description here

EDIT 3 _______________________________________________________________

Finally, this is the code that has worked for me:

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

The conflict was caused by definitions that I had used in another book by which I got the point to the right of the number of titles, but not in the TOC (the points that I have marked here with ** strong. text ** to highlight them):

% Section style definition
\titleformat{\section}[runin]
{\normalsize \bfseries}
{\color{black} \S \thesection **strong . text**}
{1ex}{\color{black}}[\qquad]

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

When trying to get the dot after the section number, etc., in the TOC, having forgotten the above definitions, I got these strange results.

I apologize to all of you who have so generously given some of your precious time trying to help me. With your collaboration, seeing that you got correct results and I did not, I was forced to carefully review my code (quite cumbersome) and thus get to discover the cause of the error. By deleting the dots in \thesection strong . text and \thesubsection **.**, obviously, the problem disappeared.

Now it only remains to solve how to put the dot after chapter numbers in the TOC (see screenshot below):

enter image description here

EDIT 4 _______________________________________________________________

Simplifying the statement, the problem to be solved is as follows: add a dot to the right of all part, chapter, section and subsection numbers, both in headings (except for chapters, which must go without a period in headings, but not in TOC) and in TOC.

2 Answers2

1

This looks good to me (I did not test it thoroughly because I am about to leave my apartment). Even if this does not solve your problem, you can use the code as an example of how to provide a minimal working example on this site.

\documentclass{book}

% For the \blinddocument command. \usepackage{blindtext}

% https://tex.stackexchange.com/questions/3177 \renewcommand\thechapter{\arabic{chapter}.} \renewcommand\thesection{\thechapter\arabic{section}.} \renewcommand\thesubsection{\thesection\arabic{subsection}.}

\begin{document}

\tableofcontents \blinddocument

\end{document}

enter image description here

enter image description here


Chapter number without dot (untested):

\renewcommand\thechapter{\arabic{chapter}}
\renewcommand\thesection{\thechapter.\arabic{section}.}
\renewcommand\thesubsection{\thesection\arabic{subsection}.}
  • Thanks, Dr. Manuel Kuehner; the result in the TABLE OF CONTENTS is what I want to get, but the headings of sections and subsections add a duplicated dot at the end (see an image of the result in EDIT 1). – Jesús Álvarez Lobo Jun 12 '21 at 10:23
  • @JesúsÁlvarezLobo Please check my added screenshot, as you can see, it looks correct. I suggest that you take my code as a start and provide a complete (compilable) code in your question. With the fragmented information that you currently provide, it is (for me) impossible to guess what your actual problem is. You can have a look at https://tex.meta.stackexchange.com/questions/228 to see what I mean. – Dr. Manuel Kuehner Jun 12 '21 at 18:34
  • Thank you very much, again, Dr. Manuel Kuehner. You can see the final solution and the cause of the errors in may EDIT 3. – Jesús Álvarez Lobo Jun 12 '21 at 22:38
1

If I understand correctly, what you want to do is to add the dot after the number, but only in the table of contents.

In this instance, the best approach would be to modify how things are printed in the table of contents. If you look in your .toc file, you'll likely see something like:

\contentsline {chapter}{\numberline {4}Defining new commands and environments}{79}{}%

The \numberline command is what's responsible for printing the number. It reserves a certain amount of space and puts the number inside of it. What we'll do is save the definition of \numberline using \let:

\let\OldNumberline=\numberline

Then we can redefine \numberline to call the old definition but with a dot after the argument:

\RenewDocumentCommand{\numberline}{ m }{% ❶
   \OldNumberline{#1.}%
}

If you have an old LaTeX distribution (before October 2020), you should replace the line marked ❶ with

\renewcommand{\numberline}[1]{%

Also, this assumes that you're using a document class which doesn't deviate significantly from the way the standard LaTeX classes handle the table of contents. Looking at the .toc file will help verify that this approach will work.

Don Hosek
  • 14,078