2

How do I lelft-align the chapter and section, number in the ToC? My code is:

\documentclass[12pt]{report}

\usepackage{tocloft}
\makeatletter
\renewcommand{\numberline}[1]{#1~}

\begin{document}
\tableofcontents

\chapter{A}
\section{One section}
\addtocounter{section}{9}
\section{Other section}

\addtocounter{chapter}{9}
\chapter{B}
\section{Hello}
\addtocounter{section}{9}
\section{Next}

\end{document}

enter image description here

and I want

 1.1 One section
1.11 Ohter section

and the same for chapters.

1
1

The following solution is based on example code given on pp. 11-12 of the user guide of the tocloft manual; I've just replaced X with sec and chap, respectively. Feel free to adjust the initial values of \mylenchap and \mylensec to suit your needs.

enter image description here

\documentclass[12pt]{report}

\usepackage{tocloft}

\newlength\mylensec
\setlength{\mylensec}{0.75em}
\renewcommand{\cftsecpresnum}{\hfill}
\renewcommand{\cftsecaftersnum}{\hspace*{\mylensec}}
\addtolength{\cftsecnumwidth}{\mylensec}

\newlength\mylenchap
\setlength{\mylenchap}{1em}
\renewcommand{\cftchappresnum}{\hfill}
\renewcommand{\cftchapaftersnum}{\hspace*{\mylenchap}}
\addtolength{\cftchapnumwidth}{\mylenchap}

\begin{document}
\tableofcontents

\chapter{A}
\section{One section}
\addtocounter{section}{9}
\section{Another section}

\addtocounter{chapter}{9}
\chapter{B}
\section{Hello}
\addtocounter{section}{9}
\section{Next}

\end{document}
2
  • Is it possible to align left the number of chapters and not to the right as in sections? – CarlosE Oct 27 '15 at 3:40
  • @CarlosE - Absolutely: Just delete (or comment out) the instructions from \newlength\mylensec to \addtolength{\cftsecnumwidth}{\mylensec}. – Mico Oct 27 '15 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.