目录中的零件编号与零件名称分开

目录中的零件编号与零件名称分开

我根据以下内容创建了这个简化的目录很棒的帖子。

梅威瑟:

%XeLaTeX
\documentclass[11pt]{book}

\usepackage[
    paperwidth=8in,
    paperheight=10in,
    inner=0.5in,
    outer=0.5in,
    bindingoffset=0.25in,
    top=0.75in,
    bottom=1.25in,
    twoside,
    %showframe
    ]{geometry} 


% https://tex.stackexchange.com/a/35835/121944, basis of this ToC design
\usepackage{framed}
\usepackage[compact,pagestyles,clearempty]{titlesec}
\usepackage{titletoc}
\usepackage{etoolbox}

% % %
\patchcmd{\tableofcontents}{\contentsname}{\rmfamily\contentsname}{}{}

\renewenvironment{leftbar}
  {\def\FrameCommand{\hspace{26.75em}%
    {\vrule width 2pt depth 3pt}\hspace{1em}}%
    \MakeFramed{\parshape 1 0cm \dimexpr\textwidth-6em\relax\FrameRestore}\vskip2pt%
  }
 {\endMakeFramed}

\titlecontents{part}
  [0em]{\vspace*{0.3\baselineskip}}
  {\parbox{14.8em}{% mainmatter
    \hfill\huge\rmfamily\bfseries}%
   \vspace*{-2.4\baselineskip}\leftbar\MakeUppercase{\normalsize{Part~}\thecontentslabel}\\\normalsize\rmfamily}
  {\parbox{14.5em}{% frontmatter
    \hfill\Large\rmfamily\bfseries}%
   \vspace*{-1.95\baselineskip}\leftbar\MakeUppercase{\normalsize{Part~}\thecontentslabel}\\\normalsize\rmfamily}
  {\endleftbar}
% % %

\titlecontents{chapter}
  [0em]{\vspace*{0.3\baselineskip}}
  {\parbox{14.8em}{% mainmatter
    \hfill\huge\rmfamily\bfseries\thecontentspage}%
   \vspace*{-2.4\baselineskip}\leftbar\textsc{\normalsize{Story~}\thecontentslabel}\\\normalsize\rmfamily}
  {\parbox{14.5em}{% frontmatter
    \hfill\Large\rmfamily\bfseries\thecontentspage}%
   \vspace*{-1.95\baselineskip}\leftbar\normalsize\rmfamily}
  {\endleftbar}
% % %


\makeatletter\@addtoreset{chapter}{part}\makeatother%

\begin{document}

\pagestyle{empty}
\renewcommand*\contentsname{\hfill Contents \hfill}
\tableofcontents%
\thispagestyle{empty}

\frontmatter


\chapter{Introduction}
\chapter{More Intro}

\part{The first part}

\mainmatter


\chapter{First}
\chapter{Second}
\chapter{Third}
\chapter{Fourth}
\chapter{Fifth}


\addtocontents{toc}{\protect\newpage}
\part{Another part}

\chapter{First}
\chapter{Second}
\chapter{Third}
\chapter{Fourth}
\chapter{Fifth}    

\end{document}

为什么会PART I分成两行?章节的设置相同,但它们不会分成两行。另外,是否可以完全去掉 的栏\part

在此处输入图片描述

答案1

book这看起来像是和之间的某种不兼容性titletoc(或者更确切地说, 的奇怪设计book)......

写给的.toc\part

\contentsline {part}{I\hspace {1em}The first part}{v}

而对于某一章来说则是:

\contentsline {chapter}{\numberline {1}First}{1}

(注意)。然后,如果您在 之前\numberline添加,则会看到它是空的,并且 的定义接下来所做的就是,因此该行在 之后就断开了。\show\thecontentslabel\titlecontents\\Part~

这种差异源于\chapter和的定义\part。要解决这个问题,您必须\numberline在 的定义中注入\part,以便titletoc能够检测到 是什么\thecontentslabel,否则它会认为该数字属于该部分的标题。由于您已经在加载,etoolbox您可以执行以下操作:

\makeatletter
\patchcmd\@part
  {\thepart}
  {\protect\numberline{\thepart}}
  {}{\FAIL}
\makeatother

输出结果为:

PART I
The first part

至于左边的栏目,我建议解决方案,为了避免弄乱对齐:定义一个Hiddenleftbar与 相同leftbar但没有规则的 ,并将此规则用于\part。该\part条目仍将与其余条目对齐,但没有垂直规则。

输出:

在此处输入图片描述

完整代码:

\documentclass[11pt]{book}

\usepackage[
    paperwidth=8in,
    paperheight=10in,
    inner=0.5in,
    outer=0.5in,
    bindingoffset=0.25in,
    top=0.75in,
    bottom=1.25in,
    twoside,
    %showframe
    ]{geometry} 


% https://tex.stackexchange.com/a/35835/121944, basis of this ToC design
\usepackage{framed}
\usepackage[compact,pagestyles,clearempty]{titlesec}
\usepackage{titletoc}
\usepackage{etoolbox}

\makeatletter
\patchcmd\@part
  {\thepart}
  {\protect\numberline{\thepart}}
  {}{\FAIL}
\makeatother

% % %
\patchcmd{\tableofcontents}{\contentsname}{\rmfamily\contentsname}{}{}

\renewenvironment{leftbar}
  {\def\FrameCommand{\hspace{26.75em}%
    {\vrule width 2pt depth 3pt}\hspace{1em}}%
    \MakeFramed{\parshape 1 0cm \dimexpr\textwidth-6em\relax\FrameRestore}\vskip2pt%
  }
 {\endMakeFramed}

\newenvironment{Hiddenleftbar}
  {\def\FrameCommand{\hspace{26.75em}%
    \hspace{\dimexpr1em+2pt}}%
    \MakeFramed{\parshape 1 0cm \dimexpr\textwidth-6em\relax\FrameRestore}\vskip2pt%
  }
 {\endMakeFramed}

\titlecontents{part}
  [0em]{\vspace*{0.3\baselineskip}}
  {\parbox{14.8em}{% mainmatter
    \hfill\huge\rmfamily\bfseries}%
   \vspace*{-2.4\baselineskip}\Hiddenleftbar\MakeUppercase{\normalsize{Part~}\thecontentslabel}\\\normalsize\rmfamily}
  {\parbox{14.5em}{% frontmatter
    \hfill\Large\rmfamily\bfseries}%
   \vspace*{-1.95\baselineskip}\Hiddenleftbar\MakeUppercase{\normalsize{Part~}\thecontentslabel}\\\normalsize\rmfamily}
  {\endHiddenleftbar}
% % %

\titlecontents{chapter}
  [0em]{\vspace*{0.3\baselineskip}}
  {\parbox{14.8em}{% mainmatter
    \hfill\huge\rmfamily\bfseries\thecontentspage}%
   \vspace*{-2.4\baselineskip}\leftbar\textsc{\normalsize{Story~}\thecontentslabel}\\\normalsize\rmfamily}
  {\parbox{14.5em}{% frontmatter
    \hfill\Large\rmfamily\bfseries\thecontentspage}%
   \vspace*{-1.95\baselineskip}\leftbar\normalsize\rmfamily}
  {\endleftbar}
% % %


\makeatletter\@addtoreset{chapter}{part}\makeatother%

\begin{document}

\pagestyle{empty}
\renewcommand*\contentsname{\hfill Contents \hfill}
\tableofcontents%
\thispagestyle{empty}

\frontmatter


\chapter{Introduction}
\chapter{More Intro}

\part{The first part}

\mainmatter


\chapter{First}
\chapter{Second}
\chapter{Third}
\chapter{Fourth}
\chapter{Fifth}


\addtocontents{toc}{\protect\newpage}
\part{Another part}

\chapter{First}
\chapter{Second}
\chapter{Third}
\chapter{Fourth}
\chapter{Fifth}

\end{document}

相关内容