如何使目录中的章节和节数左对齐?我的代码是:
\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}
而且我要
1.1 One section
1.11 Ohter section
章节也同样如此。
答案1
以下解决方案基于手册用户指南第 11-12 页提供的示例代码;我只是分别用和tocloft
替换了。您可以随意调整和的初始值以满足您的需要。X
sec
chap
\mylenchap
\mylensec
\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}