在下面的代码中,我用\titlecontents{part}
来自定义目录中各部分的显示方式。
\titlecontents{part}
[0em]
{\normalsize\bfseries\protect\addvspace{15pt}}%
{\partname{} \thecontentslabel\brlap[\baselineskip]}%
{}%
{\enspace\titlerule\contentspage}%
目前结果如下:
您能帮我将零件标签(“我的第一部分”、“我的第二部分”)左对齐吗?
完整代码
\documentclass[12pt,oneside]{book}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[newparttoc]{titlesec}
\usepackage{titletoc}
\usepackage{stackengine}
\titleformat{\part}[display]
{\bfseries\Huge}
{\partname{} \bfseries\thepart}
{1ex}
{}
\titlecontents{part}
[0em]
{\normalsize\bfseries\protect\addvspace{15pt}}%
{\partname{} \thecontentslabel\brlap[\baselineskip]}
{}%
{\enspace\titlerule\contentspage}%
\begin{document}
\tableofcontents
\part{My first part}
\chapter{My first chapter}
\section{My first section}
\part{My second part}
\end{document}
答案1
使用您正在使用的软件包的一种方法是延迟将零件名称和编号的打印延迟到结束代码:
\documentclass[12pt,oneside]{book}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[newparttoc]{titlesec}
\usepackage{titletoc}
\usepackage{stackengine}
\titleformat{\part}[display]
{\bfseries\Huge}
{\partname{} \bfseries\thepart}
{1ex}
{}
\titlecontents{part}
[0em]
{\normalsize\bfseries\protect\addvspace{15pt}}%
{\brlap[\baselineskip]}
{}%
{\partname{} \thecontentslabel \enspace\titlerule\contentspage}%
\begin{document}
\tableofcontents
\part{My first part}
\chapter{My first chapter}
\section{My first section}
\part{My second part}
\end{document}