ToC 内容间距和相关格式

ToC 内容间距和相关格式

我正在memoir课堂上工作并创建目录,其中包含简短和(有时非常)长的章节标题。我需要:

  1. 调整部分\章节编号和标题之间的水平间距,这样无论数字\编号有多长,它们都不会重叠。较长数字标题的左侧部分不必与较短数字标题对齐。我更喜欢间距是自动/可调整的(取决于部分或章节的数字/编号)。谢谢。 章节号和标题重叠 在此处输入图片描述
  2. 有时两个章节标题之间会随机出现不必要的垂直间距。 不需要的垂直间距

修复它们的正确方法是什么?我尝试在这里搜索相同的问题,但仍然没有找到。意外/不必要的垂直间距仍然令人困扰。谢谢。

\documentclass[12pt,twoside]{memoir}
\usepackage[paperwidth=140mm, paperheight=210mm, margin=20mm]{geometry}
\usepackage{titletoc}

\renewcommand\thepart{\arabic{part}}

% simulate larger part and chapter number
\setcounter{part}{50}
\setcounter{chapter}{1200}

\begin{document}

\tableofcontents

\part{This is My First Part}
\chapter{This is first chapter}
\chapter{This is very very long chapter title}
\chapter{Next chapter goes here}

\part{This is My Second Chapter}
\chapter{Very long chapter title also goes here}
\chapter{Another chapter goes here}
\chapter{Another chapter goes here}
\chapter{Another chapter goes here}

% ...and so on...

\end{document}

更新:

除了我的 Pastebin,这里还有复制的main.tex。希望这能有所帮助。谢谢。

\documentclass[12pt,twoside]{memoir}
\usepackage[paperwidth=140mm, paperheight=210mm, margin=20mm]{geometry}
\usepackage{libertine}
\usepackage{graphicx}
\usepackage[svgnames]{xcolor}
\usepackage{framed}
\usepackage{fourier-orns}
\usepackage{bbding}
\usepackage{pdfpages}
\usepackage{lipsum}

% quote
\newcommand*\openquote{\makebox(25,-22){\scalebox{5}{``}}}
\newcommand*\closequote{\makebox(25,-22){\scalebox{5}{''}}}
\colorlet{shadecolor}{Azure}

\makeatletter
\newif\if@right
\def\shadequote{\@righttrue\shadequote@i}
\def\shadequote@i{\begin{snugshade}\begin{quote}\openquote}
\def\endshadequote{%
  \if@right\hfill\fi\closequote\end{quote}\end{snugshade}}
\@namedef{shadequote*}{\@rightfalse\shadequote@i}
\@namedef{endshadequote*}{\endshadequote}
\makeatother
% END quote setting

\usepackage{type1cm}
\usepackage{lettrine}
\usepackage{pdfpages}

\chapterstyle{dash}

\usepackage{textcomp}
\usepackage{gensymb}

\renewcommand{\cftchapterfont}{\normalfont}

% ToC Setting
% http://tex.stackexchange.com/questions/201358/styling-toc-dot-leader-using-emdash-and-other-formatting-requirements
% Redefinitions of \part-entry in ToC
% \renewcommand{\cftpartname}{Part~}
\renewcommand{\cftpartname}{Part~}
\renewcommand{\cftpartaftersnum}{:}
\renewcommand{\cftpartleader}{---}
\renewcommand{\cftpartformatpnum}[1]{%
  \cftpartformatpnumhook{#1}%
  {\cftpartpagefont #1}}
\renewcommand{\cftpartafterpnum}{\hfill\null}

% Redefinition of \chapter-entry in ToC
% \renewcommand{\cftchaptername}{Chapter~}
% \renewcommand{\cftchapteraftersnum}{:}
\renewcommand{\cftchaptername}{}
\renewcommand{\cftchapteraftersnum}{.}
\renewcommand{\cftchapterleader}{---}
\let\oldcftchapterfont\cftchapterfont
\renewcommand{\cftchapterfont}{\oldcftchapterfont\mdseries}
\renewcommand{\cftchapterformatpnum}[1]{%
  \cftchapterformatpnumhook{#1}%
  {\cftchapterpagefont #1}}
\let\oldcftchapterpagefont\cftchapterpagefont
\renewcommand{\cftchapterpagefont}{\oldcftchapterpagefont\mdseries}
\renewcommand{\cftchapterafterpnum}{\hfill\null}

% Distance between part and chapter
\setlength{\cftbeforepartskip}{1em} % part
\setlength{\cftbeforechapterskip}{3pt} % chapter

% Arabic-style page numbering
% http://tex.stackexchange.com/questions/129592/add-parts-to-the-table-of-contents
\renewcommand\thepart{\arabic{part}}

% change font size of ToC item & number
% \renewcommand{\cftpartfont}{\Large\bfseries}
\renewcommand{\cftpartfont}{\normalsize\bfseries}
\renewcommand{\cftpartpagefont}{\normalsize\bfseries}

% GOOD (by Werner)
% http://tex.stackexchange.com/questions/201940/toc-content-spacing-and-related-formatting?noredirect=1#comment470627_201940
\renewcommand{\partnumberlinebox}[2]{#2 }
\renewcommand{\chapternumberlinebox}[2]{#2 }

% Past:
%\setlength{\cftchapternumwidth}{2em}
%\setlength{\cftpartnumwidth}{2em}

% --- END ToC settings

% RUNNING HEADER
% The following code have been found in Peter Wilsons Memoir manual in chapter 7 (page127)
\makepagestyle{My_pagestyle} % Create a new pagestyle

% Following code to edit the pagestyle
\makepsmarks{My_pagestyle}{\nouppercaseheads

% This is where we specify what \leftmark and \rightmark contains
%\createmark{chapter}{both}{nonumber}{}{\space}
%\createmark{section}{right}{nonumber}{}{\space}
% Change "shownumber" to "nonumber" if you don't want the chapter/section number displayed at the header.
\createmark{title}{left}{nonumber}{}{\space}
\createmark{chapter}{right}{nonumber}{}{\space}
\createplainmark{toc}{both}{\contentsname}
\createplainmark{lof}{both}{\listfigurename}
\createplainmark{lot}{both}{\listtablename}
\createplainmark{bib}{both}{\bibname}
\createplainmark{index}{both}{\indexname}
\createplainmark{glossary}{both}{\glossaryname}}
% Might want to keep those, see the manual for further information.

% The following is where you tweek your header
% http://hstuart.dk/2007/06/12/styling-the-page-footer-and-header/
% For verso pages
\makeevenhead{My_pagestyle}{\normalfont\thepage\hskip.5cm\vrule\hskip.5cm\footnotesize\Booktitle}{}{}
% For recto pages
\makeoddhead{My_pagestyle}{}{}{\footnotesize\rightmark\hskip.5cm\vrule\hskip.5cm\normalfont\thepage}

% Activate your new pagestyle
\pagestyle{My_pagestyle}

% --- END

% The 'Part' page
% http://tex.stackexchange.com/questions/49512/part-style-in-memoir-class/49534#49534
\renewcommand\partname{Part}
\renewcommand*{\partnamefont}{\normalfont\large} % part name
\renewcommand*{\partnumfont}{\normalfont\large} % part number
\renewcommand*{\parttitlefont}{\normalfont\LARGE} % part title
\renewcommand{\midpartskip}{\par\parbox{0.5in}{\hrulefill}\par} 

\renewcommand{\beforepartskip}{\vspace*{\fill}}
\renewcommand{\afterpartskip}{\vspace*{\fill}}

% Set book title and the writer's name
% http://tex.stackexchange.com/questions/195863/include-document-title-in-memoir-class-header
% http://latex-community.org/forum/viewtopic.php?f=47&t=15857
\def\Booktitle{My book title goes here}
\title{\Booktitle}
\author{The writer's name}
\date{}

% Let's do it
\begin{document}

\frontmatter

% ENDORSEMENT
\pagestyle{empty}
\include{./include/00-prelims-pages/endorsement}
\cleardoublepage % Start a new odd page (manually)

% BOOK TITLE
\include{./include/00-prelims-pages/booktitle-01}
\cleardoublepage % Start a new odd page (manually)
\include{./include/00-prelims-pages/booktitle-02}

% BOOK INFO, ISBN, ETC
\include{./include/00-prelims-pages/kdt}

% DEDICATION
\include{./include/00-prelims-pages/dedication}

\pagestyle{My_pagestyle}

% FOREWORDS
\include{./include/00-prelims-pages/intro}
\cleardoublepage % Start a new odd page (manually)

% TOC
\tableofcontents

% SET PAGE NUMBERING (1, 2, 3.. for main content)
\mainmatter

% PROLOG
\include{./include/00-prelims-pages/prolog}


% PART 1
\part{This is Part}
\include{./include/part-01/01}
\include{./include/part-01/02}
\include{./include/part-01/03}
\include{./include/part-01/04}
\include{./include/part-01/05}
\include{./include/part-01/06}

% PART 2
\part{Part}
\include{./include/part-02/01}
\include{./include/part-02/02}
\include{./include/part-02/03}
\include{./include/part-02/04}
\include{./include/part-02/05}
\include{./include/part-02/06}
\include{./include/part-02/07}
\include{./include/part-02/08}
\include{./include/part-02/09}
\include{./include/part-02/10}
\include{./include/part-02/11}

% PART 3
\part{Part}
\include{./include/part-03/01}
\include{./include/part-03/02}
\include{./include/part-03/03}
\include{./include/part-03/04}

% ...and so on...

% ABOUT THE WRITER
\cleardoublepage % Start a new odd page (manually)
\pagestyle{plain}
\include{./include/about-writer}

% ...and so on...

\end{document}

答案1

您的最小示例仅复制了问题 (1),而不是 (2)。要解决 (1),请添加

\renewcommand{\partnumberlinebox}[2]{#2 }
\renewcommand{\chapternumberlinebox}[2]{#2 }

到您的序言。它允许在\parts 和\chapters 的数字周围设置灵活的间距,从而有效地放弃了将部分/章节编号放置在由 给出的(固定)宽度的框内的要求#1

在此处输入图片描述

\documentclass{memoir}
\renewcommand\thepart{\arabic{part}}
\renewcommand{\partnumberlinebox}[2]{Part~#2 }
\renewcommand{\chapternumberlinebox}[2]{#2 }

% simulate larger part and chapter number
\setcounter{part}{50}
\setcounter{chapter}{1200}

\begin{document}

\tableofcontents

\part{This is My First Part}
\chapter{This is first chapter}
\chapter{This is very very long chapter title}
\chapter{Next chapter goes here}

\part{This is My Second Chapter}
\chapter{Very long chapter title also goes here}
\chapter{Another chapter goes here}
\chapter{Another chapter goes here}
\chapter{Another chapter goes here}

% ...and so on...

\end{document}

在上面的例子中,我也在每个\part类似条目前面添加了“-like” 。Part~

答案2

沃纳的回答看起来很权威,但是当我尝试的时候,我得到了错误

! LaTeX Error: \partnumberlinebox undefined.

咨询回忆录手册告诉我正确的咒语实际上是

\renewcommand\partnumberline[1]{#1\hspace{1em}}

对我来说确实效果很好!这是我的测试用例:

\documentclass{memoir}
% \renewcommand\partnumberlinebox[2]{#2\hspace{1em}}  % attempt 1, failed
% \renewcommand\partnumberline[1]{#1\hspace{1em}}     % attempt 2, worked

\begin{document}
\tableofcontents
\part{First}
\part{Second}
\part{Third}
\part{Fourth}
\end{document}

看起来\partnumberline至少在memoir.cls版本2011/03/06 v3.6j(我拥有的版本)上受支持,并且\partnumberlinebox是较新的添加。我不确定为什么人们会更喜欢其中一个而不是另一个。

相关内容