编译代码时:
\documentclass[draft]{book}
% ---------------------------------------------
\usepackage{titletoc}
\contentsmargin{0pt}
\titlecontents{chapter}[0pc]%
{\addvspace{2.7ex}\fontsize{14}{14}\selectfont}%
{\contentslabel[\thecontentslabel]{0pc}\hspace{1pc}}%
{}%
{\nolinebreak\hfill\thecontentspage}
% ---------------------------------------------
\begin{document}
\tableofcontents
\chapter{A chapter}
\end{document}
我收到警告:
Overfull \hbox (7.04991pt too wide) detected at line 1
我应该做哪些改变才能消除警告?
答案1
没有0pc
足够的空间容纳章节号。对于 MWE 来说,7.1pt
似乎足以容纳1
,但在您的实际文档中,所需的空间可能会更大。
\documentclass[draft]{book}
% ---------------------------------------------
\usepackage{titletoc}
\contentsmargin{0pt}
\titlecontents{chapter}[7.1pt]% <------------------------- change here
{\addvspace{2.7ex}\fontsize{14}{14}\selectfont}%
{\contentslabel[\thecontentslabel]{7.1pt}\hspace{1pc}}% <- and here
{}%
{\nolinebreak\hfill\thecontentspage}
% ---------------------------------------------
\begin{document}
\tableofcontents
\chapter{A chapter}
\end{document}
答案2
您可以使用以下方法解决 \contentspush
:
\documentclass[draft]{book}
% ---------------------------------------------
\usepackage[showframe]{geometry}
\usepackage{titletoc}
\usepackage{calc}
\contentsmargin{0pt}
\titlecontents{chapter}[0pt]%
{\addvspace{2.7ex}\fontsize{14}{14}\selectfont
}%
{\contentspush{\phantom{11}}\contentslabel[\hfill\thecontentslabel]{2em}\hspace{1pc}}%
{}%
{\nolinebreak\hfill\thecontentspage}
% ---------------------------------------------
\begin{document}
\tableofcontents
\chapter{A First Chapter}
\setcounter{chapter}9
\chapter{Another Chapter}
\end{document}