我尝试了几个我在这个论坛中找到的目录格式示例,使用包titlesec
和,\titlecontents{chapter}
但我无法让我的书目录章节条目正确缩进,就像这样
我正在使用的代码摘录是
\documentclass{book}
% It MUST be compiled with LuaLaTex
%PAGES
\usepackage[
vcentering,
hcentering,
inner=16mm,
outer=16mm,
top=22.0mm,
bottom=15.0mm,
headsep=9.3mm,
headheight=5mm,
% showframe
]
{geometry} % Extended page layout customization
\geometry{papersize={189mm,246mm}} % Possible dimensions of textbook pages
%\usepackage[cross,a4,center]{crop} %Package to print on A4 with crop signs.
\usepackage{multicol}% handling of multicolumn in documents
\usepackage[toc]{multitoc}%enables table of contents with multiple columns
\renewcommand*{\multicolumntoc}{2}% Set two columns for the table of contents
\usepackage{emptypage} % suppresses page numbers and headings on empty pages
\usepackage{xcolor}[2007/01/21] % Driver-independent color extensions
%FONTS
\usepackage{fontspec}%LuaLaTex fonts
\setmainfont[Ligatures=TeX,ItalicFont={Apollo MT Std Italic}]{Apollo MT}
\usepackage{titletoc,xpatch}%
\usepackage[explicit]{titlesec}% An interface to sectioning commands for selection from various title styles.
%Font families
\newfontfamily\Avenir{Avenir}
\newfontfamily\AvenirLight{Avenir Light}
\newfontfamily\AvenirHeavy{Avenir Heavy}
%Chapters in TOC
\newcommand{\chaptertocfont} {\fontsize{10}{12}\color{red}\AvenirHeavy}
\newcommand{\chaptertocpagefont} {\fontsize{10}{12}\color{red}\AvenirHeavy}
\titlecontents{chapter}% section-type
[0em]% left
{\vspace*{0.6cm}}% above code
{\chaptertocfont\thecontentslabel\quad}% numbered-entry format
{}% numberless-entry format
{\hfill\chaptertocpagefont\contentspage}[]% filler-page format
\begin{document}
\tableofcontents
\chapter{Energy Conversion Systems}
\chapter{Thermodynamic Properties of Multicomponent Fluids}
\end{document}
我究竟做错了什么?
答案1
我没有你的字体。但也许你想要
\titlecontents{chapter}% section-type
[1.5em]% <- changed
{\vspace*{0.6cm}}
{\chaptertocfont\contentslabel{1.5em}}% <- changed
{\hspace*{-1.5em}}% <- changed
{\hfill\chaptertocpagefont\contentspage}[]
这里还有另一个建议,即使用 packagetocbasic
代替titletoc
。然后您可以删除 package multitoc
,这样就可以避免目录中长章节标题的连字符:
\documentclass{book}
\usepackage{lipsum}
\usepackage[
vcentering,
hcentering,
inner=16mm,
outer=16mm,
top=22.0mm,
bottom=15.0mm,
headsep=9.3mm,
headheight=5mm,
% showframe
]{geometry} % Extended page layout customization
\geometry{papersize={189mm,246mm}} % Possible dimensions of textbook pages
\usepackage{fontspec}
\usepackage{multicol}% handling of multicolumn in documents
\usepackage{tikz} % loads also xcolor, graphicx, ...
\definecolor{BlueGreen}{RGB}{7,116,159}
\definecolor{LightBlue}{RGB}{185,229,251}
\definecolor{LightGreen}{RGB}{203,231,211}
\usepackage{emptypage}
\usepackage{tocbasic}
\addtotoclist[\jobname]{toc}
\renewcommand*\tableofcontents{\listoftoc[\contentsname]{toc}}
\BeforeStartingTOC[toc]{\begin{multicols}{2}}
\AfterStartingTOC[toc]{\end{multicols}}
\DeclareTOCStyleEntry[
beforeskip=.6cm plus 1pt,
entryformat=\chaptertocfont,
pagenumberformat=\chaptertocpagefont,
raggedentrytext=true
]{tocline}{chapter}
\newcommand*{\chaptertocfont}[1]{\normalsize\bfseries\textcolor{red}{#1}}
\newcommand*{\chaptertocpagefont}[1]{\chaptertocfont{#1}}
\begin{document}
\tableofcontents
\chapter{Energy Conversion Systems}
\lipsum
\chapter{Thermodynamic Properties of Multicomponent Fluids}
\lipsum
\end{document}
结果: