目录中较长的部分名称:向左对齐

目录中较长的部分名称:向左对齐

在使用文档类书籍的项目中,我有非常长的部分标题,它们在目录中沿两行分开。我希望它们排列在左侧,紧挨着“第 X 部分”。我的部分在目录中没有页码,我还在目录中的部分标题周围添加了黑线,我想找到解决我的排列问题的方法,而不会破坏这两个东西。一个基本的工作示例如下所示:

\documentclass[11pt,a4paper,twoside]{book}
\usepackage[paper=a4paper,left=25mm,right=25mm,top=35mm,bottom=40mm]{geometry}

%Black lines around parts in TOC
\usepackage{titletoc}
\usepackage{chngcntr}
\def\contentsname{{C\MakeLowercase{ontents}}}
\titlecontents{part}[0pt]{\bfseries\protect\addvspace{15pt}\titlerule\addvspace{1.5ex}}%
{}{\partname~}{}[\addvspace{0.7ex}\titlerule\addvspace{1.5ex}]

\begin{document}

\tableofcontents

\part{This is a very very very very very very very very very very very very long part title}

\chapter{Chapter 1}
\section{Section 1.1}
\chapter{Chapter 2}
\section{Section 2.1}
\section{2.2}

\end{document}

输出如下: 在此处输入图片描述

现在,我希望部件标题的第二行与标题名称的第一行对齐。我想要的基本上是这样的

\documentclass[11pt,a4paper,twoside]{book}
\usepackage[paper=a4paper,left=25mm,right=25mm,top=35mm,bottom=40mm]{geometry}

%Black lines around parts in TOC
\usepackage{titletoc}
\usepackage{chngcntr}
\def\contentsname{{C\MakeLowercase{ontents}}}
\titlecontents{part}[0pt]{\bfseries\protect\addvspace{15pt}\titlerule\addvspace{1.5ex}}%
{}{\partname~}{}[\addvspace{0.7ex}\titlerule\addvspace{1.5ex}]

\begin{document}

\tableofcontents

\part*{This is a very very very very very very very very very very very very long part title}
\addcontentsline{toc}{part}{I\hspace*{0.4cm}This is a very very very very very very very very very very very very\newline\hspace*{1.5cm}long part title}

\chapter{Chapter 1}
\section{Section 1.1}
\chapter{Chapter 2}
\section{Section 2.1}
\section{2.2}

\end{document}

这导致了结果 在此处输入图片描述

但是,可以采用更自动化的方式,而无需通过 \newline 和 \hspace* 手动完成所有操作。

相关内容