Latex 设置目录中未编号章节的格式
我有一份有编号和无编号章节的文件。为了在TOC中区分它们,我希望未编号的章节采用斜体。我的MWE在章节标题上工作-如何将相应的页码格式化为斜体 此外,是否可以将零件1入口居中Latex 设置目录中未编号章节的格式,latex,tableofcontents,Latex,Tableofcontents,我有一份有编号和无编号章节的文件。为了在TOC中区分它们,我希望未编号的章节采用斜体。我的MWE在章节标题上工作-如何将相应的页码格式化为斜体 此外,是否可以将零件1入口居中 \documentclass[a4paper, 12pt]{report} \usepackage[titles]{tocloft} \begin{document} \tableofcontents \part{Part 1} \chapter{Numbered chapter} \chapter*{Unnum
\documentclass[a4paper, 12pt]{report}
\usepackage[titles]{tocloft}
\begin{document}
\tableofcontents
\part{Part 1}
\chapter{Numbered chapter}
\chapter*{Unnumbered chapter}
\addcontentsline{toc}{chapter}{\textit{Unnumbered chapter}}
\end{document}
您可以使用
\addtocontents{toc}
手动编写由\addcontentsline
自然完成的内容:
上述内容适用于\chapter
s,因为它们通常设置在新页面上,因此\page
将生成正确的值。但是,它不适用于
或者,定义一种新类型的ToC条目,称为chapterstar
:
\documentclass{report}
\usepackage[titles]{tocloft}
\usepackage{etoolbox}
\makeatletter
\let\l@chapterstar\l@chapter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\l@chapterstar}{\cftchapfont}{\cftchapstarfont}{}{}% Insert starred chapter font
\patchcmd{\l@chapterstar}{#2}{\cftchapstarpagefont #2}{}{}% Insert starred chapter page number font
\makeatother
\newcommand{\cftchapstarfont}{\cftchapfont\itshape}
\newcommand{\cftchapstarpagefont}{\cftchappagefont\itshape}
\begin{document}
\tableofcontents
\chapter{Numbered chapter}
\chapter*{Unnumbered chapter}
\addcontentsline{toc}{chapterstar}{Unnumbered chapter}
\end{document}
\documentclass{report}
\usepackage[标题]{tocloft}
\usepackage{etoolbox}
\马克特莱特
\让\l@chapterstar\l@chapter
%\patchcmd{}{}{}{}{}
\patchcmd{\l@chapterstar}{\cftchapfont}{\cftchapstarfont}{}{}%插入带星号的章节字体
\patchcmd{\l@chapterstar}{{2}{\cftchapstarpagefont{2}{}{}%插入带星号的章节页码字体
\Maketother
\新命令{\cftchapstarfont}{\cftchapstarfont\itshape}
\新命令{\cftchapstarpagefont}{\cftchappagefont\itshape}
\开始{document}
\目录
\第{章编号}
\第*{未编号的章节}
\addcontentsline{toc}{chapterstar}{未编号章节}
\结束{document}
上述解决方案与hyperref一起使用,更通用
\documentclass{report}
\usepackage[titles]{tocloft}
\usepackage{etoolbox}
\makeatletter
\let\l@chapterstar\l@chapter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\l@chapterstar}{\cftchapfont}{\cftchapstarfont}{}{}% Insert starred chapter font
\patchcmd{\l@chapterstar}{#2}{\cftchapstarpagefont #2}{}{}% Insert starred chapter page number font
\makeatother
\newcommand{\cftchapstarfont}{\cftchapfont\itshape}
\newcommand{\cftchapstarpagefont}{\cftchappagefont\itshape}
\begin{document}
\tableofcontents
\chapter{Numbered chapter}
\chapter*{Unnumbered chapter}
\addcontentsline{toc}{chapterstar}{Unnumbered chapter}
\end{document}