0

It seems like a simple problem but it is not clear how to fix it.

Consider this

\renewcommand{\thesection}{\arabic{section} ABCXYZ}
...
\tableofcontents
\section{The title of the section}

will produce an overlap between the number "1" and "The title of the section" and ABCXYZ.

The distance between the number and the title is fixed by table of contents. It is not variable. You cannot put anything there. It is of course the same issue as when the section number is too is long compared to the fixed distance: \setcounter{section}{1000}

The following solution

\makeatletter\renewcommand*\l@section{\@dottedtocline{1}{...}{...}}\makeatother

works more or less.

However it seems to reset some of the normal toc parameters.

At least it visibly resets section numbers and section titles being bold while subsection tiles and subsubsection titles are not bold. The page numbers for sections also cease to be bold. Become like subsections page numbers in the toc.

That is bad.

Wrapping in

\textbf{arabic{section}} inside \renewcommand{\thesection}

does work. But ... it cannot reach the section title.

\section{\textbf{TITLE IS HERE}}

is less than ideal for various reasons.

Q: How do we get the rest of ordinary boldface and formatting in the default toc back after renewing *l@section?

Without any packages please.

A subquestion is this: I define a length and set width of it to be the length of the ```\arabic{section} ABCXYZ'' and now, having set the section toc distance pretty large, I wish to substract this variable distance.

The result would be that section number being small does not have a large space between it and the title. It seems that \renewcommand{\thesection}{...} is the wrong place to put it. It would not affect the spacing of the section title.

Q: What else needs to be renewed and where is the correct place to paste an hspace{\correction} object to affect the section title as it appears in the table of contents.

Probably this is exactly the same place as where default formatting can also be reconstructed.

2 Answers 2

2

The definition of \l@section comes from the document class, so not a package, but not part of LaTeX exactly. I suggest you put

\makeatletter \show\l@section \makeatother

in your document to see the preexisting definition.

I would guess you are using the "article" document class, where \l@section uses bold face, and does not use \@dottedtocline at all! In the definition found in article.cls, there is a mysterious setting of

\setlength\@tempdima{1.5em}%

and that is the width of the section number (used by \numberline).

I won't post the whole definition because I don't have the latest version. But maybe you want to reconsider using a package to format the toc.

An alternative is to redefine \numberline so that it simply will not overlap the number and the title!

\makeatletter
\renewcommand\numberline[1]{%
\begingroup
 \sbox\@tempboxa{#1 }%
 \ifdim\wd\@tempboxa<\@tempdima
  \wd\@tempboxa=\@tempdima
 \fi
 \usebox\@tempboxa
\endgroup
}
1
  • 2
    Yes. Edited. But not fully converted to LaTeXy syntax. Commented Mar 20, 2020 at 9:53
1

I know you said that you don't want to use any packages but below I have used the tocloft package to indicate what could be done. The only change to the ToC is the space for sectional numbers. If you wanted other changes then the package provides many facilities (texdoc tocloft).

    % tocprob5.tex SE 533343 section numbers
\documentclass{article}
\renewcommand{\thesection}{\arabic{section} ABCXYZ}
\usepackage{tocloft}
\newlength{\mylen} 
\settowidth{\mylen}{\textbf{99 ABCXYZ}} % the space required for the section number
\setlength{\cftsecnumwidth}{\mylen} % set space for section number
\setlength{\cftsubsecnumwidth}{\mylen} % set space for subsection number
\begin{document}
\tableofcontents
\section{Section}
\subsection{Subsection}
\section{Another section}
\end{document}

I hope that you are not going to use your example redefinition of \thesection in your real document as then the first \subsection in the first \section will be numbered as "1 ABCXYZ.1" which to me looks really odd. Perhaps you will want to do some redefining of subsection numbering.

You must log in to answer this question.

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