我正在尝试使用 tocloft 将目录放在封面上:
然而,这些部分与章节标题不一致。
如何使部分标题与章节标题对齐?
笔记:抱歉,这两个代码文件各有大约 100 行代码,不是最小工作示例/MWE。尝试发布 MWE 似乎很难,所以我没有开始这样做。这些代码可以在 TexLive 2017 和 TexLive 2020 中很好地编译。
封面.tex:
\newgeometry{left=0cm,right=0cm,top=1cm,bottom=1.2cm}
\newcommand{\bolumfont}{\renewcommand{\cftpartfont}{\hfill\color{olive}}}
\newenvironment{MainTOC}{\partfont}{}
\begin{titlepage}
\begin{center}
{\fontsize{60pt}{10pt}\selectfont\color{black!60}Altai Mountains\\In A Nutshell}
\\
\color{black!60}\rule[0pt]{365pt}{0.5mm}
\\
\mbox{\Termes \large\color{black!60}Jonikrevoc Moskowic}
\addvspace{5pt}
\begin{minipage}[]{1.0\textwidth}
% \includegraphics[width=597pt]{img/altai_kutscherla_see}% You can get this image at wikipedia if you wish
\includegraphics[width=597pt]{example-image}
\end{minipage}
\end{center}
\addvspace{0pt}
\begin{center}
\begin{MainTOC}
\begin{minipage}[]{0.96\textwidth}
\noindent
\begin{minipage}[T]{0.58\textwidth}
\begin{flushright}
\renewcommand{\thepart}{\footnotesize\Alph{part}} % Make parts A B C...
\renewcommand*{\multicolumntoc}{2}
\setlength{\columnsep}{-8pt}
\cftsetpnumwidth{1em}
\setlength{\cftbeforetabskip}{0.1cm}
\renewcommand\contentsname{}
\setlength{\cftaftertoctitleskip}{0pt}
\setlength{\cftbeforepartskip}{0pt}
\setlength{\cftbeforetoctitleskip}{5pt}
\renewcommand\cftchapafterpnum{\vskip 15pt}
\renewcommand\cftsecafterpnum{\vskip 15pt}
\renewcommand{\cftdot}{} % remove dots
\renewcommand{\cftchapleader}{\,\footnotesize/} % Page Numbers next to Titles
\renewcommand{\cftpartleader}{\,\footnotesize/\:}
\renewcommand\cftpartpagefont{\color{olive}\footnotesize\bfseries}
\renewcommand{\cftpnumalign}{l}
\renewcommand{\cftpartnumwidth}{0pt}
\renewcommand{\cftpartafterpnum}{\cftparfillskip}
\renewcommand{\cftchapafterpnum}{\cftparfillskip}
\renewcommand{\cftsecafterpnum}{\cftparfillskip}
\begingroup
\makeatletter
% Redefine the \chapter* header macro to remove vertical space
\def\@makeschapterhead#1{%
{\parindent \z@ \raggedright
\footnotesize % normalfont
\interlinepenalty\@M
\footnotesize \bfseries #1\par\nobreak
\vskip 20\p@
}}
\makeatother
\begin{spacing}{0.48} % Increase spacings
\newdimen\origiwspc%
\setlength\cftparskip{1pt} % make it 2pt to ease off the line spacings
\setlength\cftbeforechapskip{-2pt}
% https://latex.org/forum/viewtopic.php?t=7701
\renewcommand{\cftpartpresnum}{Q }
\renewcommand{\cftpartaftersnum}{:}
\renewcommand{\cftchapaftersnum}{.}
\footnotesize
\tableofcontents
\end{spacing}
\endgroup
\end{flushright}
\end{minipage}%
\hspace{0.01\linewidth}%
\fbox{%
\noindent
\begin{minipage}[T]{0.34\textwidth}%
\centering
\fontsize{9}{9}
\setlength{\LTleft}{1pt}
\begin{threeparttable}
\footnotesize
\begin{tabular}{l}
% \lipsum[100] % Need to add line endings so lipsum is no use
Phasellus eu quam vitae turpis\\
Duis feugiat felis ut enim\\
Quisque scelerisque dapibus\\
sem id porttitor sodales\\
nec blandit nisl mauris at pede\\
Excepteur sint occaecat cupid\\
eprehenderit in voluptate\\
officia deserunt mollit anim\\
\end{tabular}
\end{threeparttable}
\end{minipage}
}
\end{minipage}%
\end{MainTOC}
\end{center}
\end{titlepage}
\restoregeometry
主要.tex:
%! lualatex
\documentclass[a4paper,openany,14pt,oneside,]{extbook}
\usepackage[left=1.7cm,right=1.7cm,top=2cm]{geometry}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures={TeX,Common}}
\newfontfamily{\Termes}{TeX Gyre Termes}
\usepackage{tcolorbox}
\PassOptionsToPackage{export}{adjustbox}
\usepackage{xcolor}
\PassOptionsToPackage{svgnames,cmyk,rgb}{xcolor}
\usepackage{hyperref}
\usepackage{bookmark}
\newcommand{\partfont}{\renewcommand{\cftpartfont}{\colorlet{red!80!black}{olive}}}
\hypersetup{
colorlinks=true,
linkcolor=red!80!black,
urlcolor=green!50!black,
hyperfootnotes=false,
hypertexnames,
bookmarks=true}
\usepackage{menukeys}
\usepackage{graphicx}
\usepackage{framed}
\usepackage{xparse}
\usepackage{amsmath,amssymb} % centerdot için de gerekli
\setlength{\parindent}{12pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
\usepackage{etoolbox}
\DeclareListParser{\MyListParser}{|} % $\bullet$
\usepackage{threeparttable}
\usepackage{multicol}
\usepackage{paracol}
\usepackage{setspace}
\usepackage{array}
\usepackage{graphicx} % for titlepage logo
\setcounter{secnumdepth}{0} % number chapters
\setcounter{tocdepth}{1} % list chapters, sections, subsections, etc
\makeindex
\newcommand{\ssection}[1]{%
\section[#1]{#1}} % \scshape
\newcommand{\ssubsection}[1]{%
\subsection[#1]{\raggedright\normalfont\itshape #1}}
\renewcommand{\thempfootnote}{\fnsymbol{footnote}}
\usepackage{afterpage}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\bfseries\Large}
{\filright \Huge\thechapter} % \MakeUppercase{\chaptertitlename}
{1ex}
{\titlerule\vspace{1ex}\filright}
[\vspace{1ex}] % \titlerule
\usepackage[toc]{multitoc}
\usepackage{lipsum}
% To prevent empty page after PART
\makeatletter
\renewcommand\@endpart{\vfil
\if@twoside
\null
\thispagestyle{empty}%
\newpage
\fi
\if@tempswa
\twocolumn
\fi}
\makeatother
\newcounter{descriptcount}
\renewcommand*\thedescriptcount{\arabic{descriptcount}}
\makeatletter
\renewcommand\@pnumwidth{1mm}
\makeatother
\makeatletter
\renewcommand{\@tocrmarg}{-2.55em}
\makeatother
\usepackage[]{tocloft}
% begindok
\begin{document}
\pagenumbering{roman} % I, II, III, IV, V, ...
\include{coverpage}
\pagenumbering{roman} % I, II, III, IV, V, ...
\Termes
\lipsum[500]
\subsection{Foreword}\addcontentsline{toc}{chapter}{Foreword}
\lipsum[20]
\pagenumbering{arabic}
\part{Intro}
\Termes
\chapter{Etymology and names}
\lipsum[20]
\chapter{Geography}
\lipsum[20]
\chapter{Fauna}
\lipsum[20]
\chapter{History}
\lipsum[20]
\chapter{World heritage site}
\lipsum[20]
\chapter{Geology}
\lipsum[20]
\chapter{Seismic Activity}
\lipsum[20]
\chapter{Visiting Mt. Altai}
\lipsum[20]
\part{Packing up the baggage}
\chapter{Here We Go}
\lipsum[20]
\part{Oasis}
\chapter{Sip of wine}
\lipsum[20]
\part{What Else}
\chapter{This isn't last}
\lipsum[20]
\chapter{Any questions?}
\lipsum[20]
\part{Finally...}
\chapter{Licensing terms}
\lipsum[20]
\end{document}
答案1
正如我在评论中提到的,问题似乎在于插入文件的方式不同\chapter
。\part
使用\addcontentsline
命令.toc
,\chapter
可以\numberline
通过tocloft
选项进行调整,但\part
只是在零件编号和零件标题之间放置一个常量空格。
我能想到的解决这个问题的最简单方法是重新定义命令\@part
(由调用\part
),以便它\numberline
在插入\contentsline
零件时也可以使用。
将其放在\begin{document}
之前main.tex
:
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\addcontentsline{toc}{part}{\protect\numberline{\thepart}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\bfseries \partname~\thepart
\par
\vskip 20\p@
\fi
\Huge \bfseries #2\par}%
\@endpart}
\makeatother
还需要进行一些其他更改。您需要将零件号专用的空间与章节号专用的空间相同。因此,请更改以下行:
\renewcommand{\cftpartnumwidth}{0pt}
发现coverpage.tex
如下:
\renewcommand{\cftpartnumwidth}{\cftchapnumwidth}
现在您还拥有:
\renewcommand{\cftpartpresnum}{Q }
\renewcommand{\cftpartaftersnum}{:}
我不知道那里的“Q”是什么意思,但是随着这些变化,它会在零件编号前引入一个“Q”,并在其后引入一个冒号,我不确定您是否想要这样。
由于章节号已加粗,也许您希望零件号也加粗?那么您可能希望这样:
\renewcommand{\cftpartpresnum}{\bfseries}
\renewcommand{\cftpartaftersnum}{:}
(或者删除第二行,因为那里没有标点符号。)
最后,如果您还想将零件标题加粗,则必须将其添加到\cftpartfont
(实际上,您在其他地方已经对此有两种不同的定义;我正在调整其中之一,但您可以根据需要进行更改):
\renewcommand{\cftpartfont}{\bfseries\colorlet{red!80!black}{olive}}
结果是这样的:
你的问题中没有问到这个问题,但你有一个重新定义\thepart
为使用字母的行。然而,因为重新定义发生里面在一些有限的环境中(中心环境、MainTOC 环境、一些小页面等),它不会全局应用,因此在\part
使用命令时不会激活。因此,如果您确实希望使用字母而不是罗马数字作为部分,您可以改为在 main.tex 中输入类似的东西\renewcommand{\thepart}{\Alph{part}}
,再次说之前\begin{document}
。
答案2
对齐章节和部分(不更改 coverpage.tex)
(1)定义章节号宽度(之后\usepackage{tocloft}
\renewcommand{\cftchapnumwidth}{2.0em}
(2)将零件编号插入相同宽度的框中
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\addcontentsline{toc}{part}{\parbox{2em}{\thepart}#1}% changed <<<<<<<<
\else
\addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\bfseries \partname~\thepart
\par
\vskip 20\p@
\fi
\Huge \bfseries #2\par}%
\@endpart}
\makeatother