0

I want to change the section formatting to a longer one but the table of contents has it overlapping with the section. How can I fix this?

\documentclass{article}
\usepackage[utf8]{inputenc}

\renewcommand{\thesection}{some text \arabic{section}}

\begin{document}

\tableofcontents

\section{Introduction}

\section{Example}

\end{document}

Result: overlapping text in table of contents

1

2 Answers 2

1

The titletoc package offers an easy way to configure the entries to the ToC.

\titlecontents{⟨section⟩}[⟨left⟩]{⟨above-code⟩}
{⟨numbered-entry-format⟩}{⟨numberless-entry-format⟩}
{⟨filler-page-format⟩}[⟨below-code⟩]

It is possible to add text before the section number by setting the numbered entry format. This requires enclosing the text in the number in a parbox wide enough to include the chosen text and up to two-digit section numbers to keep the section titles aligned in the ToC.

To simplify this process we used the eqparbox package which makes the boxes as wide as the widest member of the group (called sect in the example).

a

\documentclass{article}

\usepackage{eqparbox} % make  boxes as wide as the widest member of the group <<<<<<<<<
\usepackage{titletoc} % added <<<<<<<<


\titlecontents{section}
[0em]
{\vspace{.25\baselineskip}}
{\eqparbox{sect}{Some Text \thecontentslabel}\enspace}{}
{\hspace{1ex}\titlerule*[5pt]{$\cdot$}\contentspage}


\begin{document}
    
\tableofcontents

\section{Introduction}

\section{Example}

\end{document} 

To check the code add more text and/or create a section numbered with two digits.

\documentclass{article}

\usepackage{eqparbox} % make  boxes as wide as the widest member of the group <<<<<<<<<
\usepackage{titletoc} % added <<<<<<<<


\titlecontents{section}
[0em]
{\vspace{.25\baselineskip}}
{\eqparbox{sect}{Some more Text \thecontentslabel}\enspace}{}
{\hspace{.5em}\titlerule*[10pt]{$\cdot$}\contentspage}


\begin{document}
    
\tableofcontents

\section{Introduction}

\section{Example}

\setcounter{section}{9} % to create section 10

\section{Conclusion}
\end{document} 

d

Sometimes it is necessary to compile twice when changing the configuration.

0

Use the tocloft package for configuring ToC, LoF and LoT entries.

% tocsecnumprob.tex  SE 666590

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tocloft}
\addtolength{\cftsecnumwidth}{5em} % more space for section number in ToC

\renewcommand{\thesection}{some text \arabic{section}}

\begin{document}

\tableofcontents

\section{Introduction}

\section{Example}

\end{document}

You must log in to answer this question.

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