0

Anyone knows how to solve this? The problem is that the number is very close to the title when the number reaches 10. I will add an image to reference this. Thanks in advance!

enter image description here

These are all the packages (and the type of document) I used:

\documentclass[12pt]{article}
\usepackage{amsmath} 
\usepackage{graphicx} 
\usepackage[margin=1in]{geometry} 
\usepackage{cite} 
\usepackage{float}
\usepackage[final]{hyperref}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage[spanish]{babel}
\usepackage[bottom]{footmisc}
\usepackage{titlesec}
\usepackage{hyperref}
\usepackage{soul}
\usepackage{comment}
\usepackage{subfiles}

NOTE: This question is related but that solution doesn't work perfectly because it changes the spacing and removes the period after the number. I only want to change that space between number and title. Thanks!

enter image description here

EDIT: Added MWE:

\documentclass[12pt]{article}
\usepackage{amsmath} 
\usepackage{graphicx}
\usepackage[margin=1in]{geometry}
\usepackage{cite} 
\usepackage{float}
\usepackage[final]{hyperref}
\usepackage{lipsum}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage[spanish]{babel}
\setlength{\parindent}{0em}
\setlength{\parskip}{.5em}
\renewcommand{\baselinestretch}{1.35}
\usepackage[bottom]{footmisc}
\usepackage{titlesec}
\usepackage{hyperref}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}

\begin{document}

\thispagestyle{empty} \setlength\headheight{0pt} \begin{center} {\Large\bfseries Resume\par} \vspace{0.5cm} \end{center}

\tableofcontents \pagebreak

\section{A} \section{B} \section{C} \section{D} \section{E} \section{F} \section{G} \section{H} \section{I} \section{J} \section{K} \section{L} \section{M}

\end{document}

This will display:

enter image description here

2 Answers2

1

The solution remains the same as in Roman numerals become “too wide” in table of contents, except for some shuffling of the package loading:

enter image description here

\documentclass{article}

\usepackage{tocloft} \usepackage[spanish]{babel} \usepackage{hyperref}

\setcounter{secnumdepth}{4} \setcounter{tocdepth}{4} \setlength{\cftsecnumwidth}{3em}

\begin{document}

\tableofcontents

\clearpage

\section{A} \subsection{AA} \section{B} \section{C} \section{D} \section{E} \section{F} \section{G} \section{H} \section{I} \section{J} \section{K} \section{L} \section{M}

\end{document}


You can also adjust the spacing manually by patching \l@section:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\l@section}% <cmd>
  {1.5em}% <search>
  {2em}% <replace>
  {}{}% <success><failure>
\makeatother
Werner
  • 603,163
  • The spacing is completely separate from the indentation. You can adjust \baselinestretch or use setspace (latter is preferred). – Werner Dec 17 '20 at 18:57
  • @santilococo: You can use your previous settings: \setlength{\parskip}{.5em} \renewcommand{\baselinestretch}{1.35} if you wish. – Werner Dec 17 '20 at 19:06
  • @santilococo: tocloft does manage all of the ToC content; even setting the vertical spacing between certain elements. Try adding \setlength{\cftparskip}{.5em} \addtolength{\cftbeforesecskip}{.5em} as part of your settings. It specifies the \parskip within the ToC and the skip before a section. You can adjust it to suit your needs. – Werner Dec 17 '20 at 19:54
  • @santilococo: I've added an addendum to my answer showing how to change the default spacing from 1.5em for the number to 2em. You can use that option if all the other settings are giving you issues. – Werner Dec 17 '20 at 19:58
0

Use the tocloft package and \cftsecnumwidth to change the space for section numbers in the ToC.

EDIT

Changed the answer to meet the OP's desire (in a comment) to have extra space between the ToC entries.

% tocnumprob.tex rev 2 SE 575762

\documentclass{article} \usepackage{comment}

\begin{comment} \usepackage[explicit]{titlesec}

\titleformat{name=\section}[block] {\normalfont\normalsize\bfseries}{\thesection~~#1}{1em}{}[ \addcontentsline{toc}{section}{\thesection~#1}] \end{comment}

\usepackage{tocloft} %\setlength{\cftsecnumwidth}{3.5em} % change this to suit more space for section numbers \makeatletter \renewcommand{\numberline}[1]{% % don't put section numbers in a box {@cftbsnum #1@cftasnum\hfil}@cftasnumb} \makeatother \renewcommand{\cftsecaftersnum}{\hspace{1em}} % change this to suit space after section number

\setlength{\cftparskip}{\baselineskip} % put more space between entries

\begin{document}

\tableofcontents \pagebreak

\section{A} \section{B} \section{C} \section{D} \section{E} \section{F} \section{G} \section{H} \section{I} \section{J} \section{K} \section{L} \section{M} \subsection{Subsection} \end{document}

\section{Fisrt} \setcounter{section}{98999} \section{section}

\end{document}

enter image description here

Peter Wilson
  • 28,066