2017-01-03 2 views
0

У меня есть документ с пронумерованными и ненумерованными главами. Чтобы отличить их друг от друга в ТОС, я хотел бы, чтобы ненумерованные главы были выделены курсивом. Мой MWE работает над заголовком главы - как я могу отформатировать соответствующий номер страницы курсивом?Форматирование ненумерованных глав в TOC

Кроме того, можно ли центрировать вход в часть 1?

\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} 

ответ

1

Вы можете написать, что, естественно, делается \addcontentsline вручную с помощью \addtocontents{toc}:

enter image description here

\documentclass{report} 

\usepackage[titles]{tocloft} 

\begin{document} 

\tableofcontents 

\chapter{Numbered chapter} 

\chapter*{Unnumbered chapter} 
\addtocontents{toc} 
    {\protect\contentsline{chapter}{\textit{Unnumbered chapter}}{\textit{\thepage}}} 

\end{document} 

выше должны работать для \chapter с, так как они, как правило, устанавливается на новой странице и, следовательно, \thepage приведет к правильному значению. Однако он не работает с hyperref.

В качестве альтернативы, определить новый тип ТОС записи называется chapterstar:

\documentclass{report} 

\usepackage[titles]{tocloft} 
\usepackage{etoolbox} 

\makeatletter 
\let\[email protected]\[email protected] 
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>} 
\patchcmd{\[email protected]}{\cftchapfont}{\cftchapstarfont}{}{}% Insert starred chapter font 
\patchcmd{\[email protected]}{#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} 

выше решение работает с hyperref и более общий характер.

Смежные вопросы