我使用以下代码(titletoc 包)自定义目录的“部分条目”。您能帮我将页码推到右侧,以便与其他页码对齐吗?
\titlecontents{part}[0pt]{
\protect\addvspace{15pt}%
}{}{\large\bfseries\partname{} }{$\;$\titlerule$\;$\large\bfseries\thecontentspage}[]
完整的工作示例
\documentclass{book}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{titletoc}
\titlecontents{part}[0pt]{
\protect\addvspace{15pt}%
}{}{\large\bfseries\partname{} }{$\;$\titlerule$\;$\large\bfseries\thecontentspage}[]
\begin{document}
\tableofcontents
\part{Part 1}
\chapter{Chapter 1}
\section{Section 1.1}
\section{Section 1.2}
\chapter{Chapter 2}
\section{Section 2.1}
\section{Section 2.2}
\part{Part 2}
\chapter{Chapter 1}
\section{Section 1.1}
\section{Section 1.2}
\chapter{Chapter 2}
\section{Section 2.1}
\section{Section 2.2}
\end{document}
答案1
这就是你想要的吗?你的代码没有在每个新部分重置章节编号,所以我使用了chngcntr
包。
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage{titletoc}
\usepackage{chngcntr}
\counterwithin*{chapter}{part}
\titlecontents{part}[0pt]{\large\bfseries\protect\addvspace{15pt}}%
{}{\partname{}}%
{\enspace\titlerule \contentspage}%
\begin{document}
\tableofcontents
\part{Part One}
\chapter{Chapter the First}
\section{Section 1.1}
\section{Section 1.2}
\chapter{Chapter the Second}
\section{Section 2.1}
\section{Section 2.2}
\part{Part Two}
\chapter{Chapter the First}
\section{Section 1.1}
\section{Section 1.2}
\chapter{Chapter the Second}
\section{Section 2.1}
\section{Section 2.2}
\end{document}