当我在章节开头制作部分表格时,第一个包含“\paragraph”的章节的页码无法与其他章节的页码对齐。
\documentclass[openany]{book}
\raggedbottom %reduce underfull \vbox
\usepackage{titlesec, titletoc}
\titlelabel{\thetitle\quad}
%change the part format in book
\titleformat{\part}[frame]{\normalfont\huge\bfseries}{\partname\ \thepart }{20pt}{\Huge\centering}
%change the part format in table of contents
\titlecontents{part}%
[0pt]{\sffamily\bfseries\huge\protect\addvspace{25pt}\titlerule\addvspace{1.5ex}}%remove rule if you like
{}{\partname~}
{\hfill\contentspage}%replaced with {} if don't want page number for parts
[\addvspace{0.7ex}\titlerule\addvspace{10pt}]%remove rule if you like
%change the chapter format in table of contents
\titlecontents{chapter}%
[0pt]{\sffamily\bfseries\large\protect\addvspace{10pt}}%
{\chaptertitlename\ \thecontentslabel~}{}
{\hfill\contentspage}%
[\addvspace{1.5ex}]%
%change the appendix name from chapter to appendix
\makeatletter
\g@addto@macro{\appendix}{%
\renewcommand\chaptername{Appendix}%
\addtocontents{toc}{\protect\renewcommand*{\protect\chaptername}{\protect\appendixname}}%
}
\makeatother
%force paragraph newline
\titleformat{\paragraph}[hang]{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
%customize page layout
\usepackage[a4paper, left=3cm, right=3cm]{geometry}
%color
\usepackage[dvipsnames]{xcolor}
%page headers and footers left,right,odd,even
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{\normalfont\small\rmfamily\nouppercase{\leftmark}}
\fancyhead[LO]{\normalfont\small\rmfamily\nouppercase{\rightmark}}
\fancyhead[LE,RO]{\thepage}
%revise\@endpart macro
\makeatletter
\def\@endpart{\bigbreak}
\makeatother
%define a new command named cdotfill
\makeatletter
\newcommand\cdotfill{%
\leavevmode\cleaders\hb@[email protected]{\hss$\cdot$\hss}\hfill\kern\z@
}
\makeatother
% to make a mini table by package titletoc
\newcommand\startmycontents{
\vspace*{3pc}
\startcontents
{\normalsize\bfseries\contentsname\endgraf\vspace{5pt}}
\contentsmargin{1em}
\titlerule
\addvspace{0.3ex}
\printcontents{l}{1}{\setcounter{tocdepth}{1}}
\addvspace{0.2ex}
\titlerule
\addvspace{3ex}
}
\titleformat{\chapter}[display]{\normalfont\bfseries\huge}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlecontents*{lsection}[4pt]{\small}{\thecontentslabel~}{}{\cdotfill\contentspage}[\endgraf]%
\begin{document}
\frontmatter
\tableofcontents
\chapter*{New features in C++11}
\mainmatter
\chapter{Getting Started}
\startmycontents
This chapter introduces most of the basic elements of C++: types, variables,
expressions, statements, and functions. Along the way, we’ll briefly explain how to
compile and execute a program.
\section{Writing a Simple C++ Program}
\subsection{Compiling and Executing Our Program}
\section{A First Look at Input/Output}\label{a first look at input/output}
\section{A Word about Comments}
\section{Flow of Control}
\subsection{The while Statement}\label{subsec:the while statement}
\subsection{The for Statement}
\section{Introducing Classes}
\subsection{The Sales\_item Class}\label{subsec:the salesitem class}
\paragraph{Adding Sales\_items}
\subsection{A First Look at Member Functions}
\section{The Bookstore Program}
\section*{Defined Terms} \markright{Defined Terms} \addcontentsline{toc}{section}{Defined Terms}
\stopcontents
\pagebreak\pagecolor{White}
\backmatter
\chapter{Index}
\end{document}
然后,如果我将“\paragraph{Adding Sales_items}”移至“编写一个简单的 C++ 程序”部分,代码将给出如下部分表:
谁能帮我找到对齐页码的方法并告诉我这种现象的原因?