![目录中的对齐方式 (\titlecontents)](https://linux22.com/image/291405/%E7%9B%AE%E5%BD%95%E4%B8%AD%E7%9A%84%E5%AF%B9%E9%BD%90%E6%96%B9%E5%BC%8F%20(%5Ctitlecontents).png)
在下面的代码中,我用\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}