我对目录的格式有一个特定的要求。
我使用的是书籍类。要求是(其中 # 是页码),而不是1 Introduction #
目录。Chapter 1: Introduction #
在文中,而不是Chapter 1 (new line) Introduction
要求是Chapter 1: Introduction
。
实现这一目标的最简单的方法是什么?
\documentclass{book}
\usepackage{blindtext}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{Introduction}
\section{My subsection title}
\blindtext[1]
\end{document}
答案1
此版本不使用附加包。
\documentclass{book}
\usepackage{blindtext}
\makeatletter
\renewcommand*\l@chapter[2]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\setlength\@tempdima{1.5em}%
\begingroup
\def\numberline##1{\hb@xt@\@tempdima{\@chapapp~##1:\hfil}}%
\advance\@tempdima by 4.5em
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries
\advance\leftskip\@tempdima
\hskip -\leftskip
#1\nobreak\hfil
\nobreak\hb@xt@\@pnumwidth{\hss #2%
\kern-\p@\kern\p@}\par
\penalty\@highpenalty
\endgroup
\fi}
\def\@makechapterhead#1{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\interlinepenalty\@M
\if@mainmatter
\Huge\bfseries \@chapapp\space \thechapter: #1\par\nobreak
\par\nobreak
\vskip 20\p@
\else
\Huge \bfseries #1\par\nobreak
\fi
\fi
\vskip 40\p@
}}
\makeatother
\begin{document}
\frontmatter
\tableofcontents
\chapter{Abstract}
\mainmatter
\chapter{Introduction}
\blindtext[1]
\chapter{A very very very very very very very very very long title}
\end{document}
答案2
由于您正在使用book
类,因此下面的方法可以达到目的:
\documentclass{book}
\usepackage{titlesec}% <-- to change chapter, section,... style
\usepackage[titles]{tocloft}% <-- changes to ToC
\usepackage{blindtext}
%rename \thechapter to easy display in ToC
\renewcommand{\cftchappresnum}{Chapter }
%punctuation for chapters in ToC
\renewcommand{\cftchapaftersnum}{:}
%Indentation for chapters in ToC
%separation between the colon and "Introduction" is given in the second argument. The indentation for the whole line is given in the first argument
\cftsetindents{chapter}{0ex}{13.5ex}
%Definition of the new chapter style
\titleformat{\chapter}[hang]{\huge}{Chapter \thechapter :}{1ex}{}
%not sure if sections, subsections, etc. need an specific format
%this for example will change the output of sections
%\titleformat%
%{\section} %<-- command, this will modify section
%[hang] %<-- shape, for section it would be hang too
%{\Large\bfseries} %<-- format
%{\thesection} %<-- label, the number before the actual section name
%{1ex} %<-- horizontal separation between label and title
%{} %<-- code preceding the title body
%[after code] %<-- code following the title body
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{Introduction}
\section{My subsection title}
\blindtext[1]
\end{document}
为了更好地缩进较长的章节标题,您可以查看这个问题
答案3
使用类(和类memoir
的超集)。book
report
% chaptocstyleprob.tex SE 567907
\documentclass{memoir}
\usepackage{blindtext}
%% styling the chapter titles
\makechapterstyle{yourstyle}{%
\renewcommand{\afterchapternum}{: }
}
%% styling the chapter ToC entries
\setlength{\cftchapternumwidth}{1.8em}
\renewcommand{\cftchaptername}{Chapter\space}
\renewcommand{\cftchapteraftersnum}{:}
\begin{document}
\chapterstyle{yourstyle} %% use your chapter style
\frontmatter
\tableofcontents
%% or \tableofcontents* if you don't want the ToC listed in the ToC
\mainmatter
\chapter{Introduction}
\blindtext[1]
\setcounter{chapter}{11}
\chapter{Another chapter}
\end{document}
该类memoir
提供了很多方法来改变文档的外观。请阅读手册(> texdoc memoir
)以了解更多信息。