切换 TOC 和 LOT 标题的字体和颜色

切换 TOC 和 LOT 标题的字体和颜色

我想要做的事情似乎很简单,但也超出了我的能力范围:更改 TOC 标题Contents和 LOT 标题使用的字体和颜色List of Tables(参见所附屏幕截图)。

我希望我在章节中使用的 Candara 字体和我为它们选择的颜色可以用于“目录”和“表格列表”

% PREAMBLE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[oneside,centered,twocolumn]{book}
%\documentclass[a4paper,oneside,centered,twocolumn]{book}
\special{papersize=215.9mm,279.4mm}
%\usepackage[top=3cm, bottom=3.2cm, left=2.5cm, right=2.5cm]{geometry}

\usepackage[english]{babel}
\usepackage{tocloft} % Customization of TOC LOF LOT
\usepackage[table,xcdraw]{xcolor} % For shading in tables
\usepackage{pdfcolmk}
\usepackage{multirow}

%\usepackage{lscape} %to put the long table of dwellings sideways
%\usepackage{wallpaper}
\usepackage{blindtext}
%\usepackage{showframe}

\usepackage{textcomp}
\usepackage{pdfpages}
\usepackage{ltablex}
\usepackage{nicefrac} % to write fractions
\usepackage{attrib} % For source of quotations
\usepackage{lettrine} % For NewThought formatting
\usepackage{array} % To define width of columns in long table
\usepackage{booktabs} % Nicer spacing in columns
\usepackage{siunitx} % To write Celsius, etc.
\usepackage{enumitem} % To create item lists
\usepackage{caption} % To change way captions are labelled
\usepackage{scrextend}
\usepackage{threeparttable} % For table notes + To allow footnote material to stay with the tabular environment
\usepackage{etoolbox} % To make table footnote font smaller
\usepackage{threeparttablex}
\appto\TPTnoteSettings{\footnotesize}
\usepackage{textcomp} % For Numero symbol
\usepackage[T1]{fontenc}
\usepackage{titlesec,color}
\usepackage{xcolor}
\usepackage[linguistics,edges]{forest}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{titling}
\usepackage{fontspec}
\usepackage{newpxtext} % Font for document instead of obsolete Palatino
\usepackage{fancyhdr}
\usepackage{etoolbox}

% To make TOC in two columns and List of Tables into one column.
\usepackage{multitoc}
\makeatletter
\renewcommand*{\@starttoc}[1]{%
            \ifthenelse{\equal{#1}{toc}}{%
            \ifnum\multicolumntoc>1
            \begin{multicols}{\multicolumntoc}%
                \@multitoc@starttoc{#1}%
            \end{multicols}%
            \else
            \@multitoc@starttoc{#1}%
            \fi}{}%
        \ifthenelse{\equal{#1}{lot}}{%
            \ifnum\multicolumnlot>1
            \begin{multicols}{\multicolumnlot}%
                \@multitoc@starttoc{#1}%
            \end{multicols}%
            \else
            \@multitoc@starttoc{#1}%
            \fi}{}%
        \ifthenelse{\equal{#1}{lof}}{%
            \ifnum\multicolumnlof>1
            \begin{multicols}{\multicolumnlof}%
                \@multitoc@starttoc{#1}%
            \end{multicols}%
            \else
            \@multitoc@starttoc{#1}%
            \fi}{}%
}
\makeatother
\renewcommand{\multicolumnlot}{1}


% CHAPTER, SECTION, SUBSECTION STYLE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newfontfamily\headingfont[]{Candara}
\titleformat{\chapter}[display]
{\bfseries\color{blue}\filcenter\fontsize{35}{35}\headingfont} % Size of Chapter1&Chapter
{\huge\MakeUppercase\headingfont{\chaptertitlename} \thechapter}
{12pt}
{\tikz[remember picture,overlay]\node[inner sep=0pt] at ($(current page.north) +
        (0pt,-117pt)$) {\includegraphics[width=14cm]{chapterHead_10cm}};}
\titlespacing{\chapter}{0pt}{50mm}{42.5mm}
\titleformat*{\section}{\LARGE\color{orange}\headingfont}
\titleformat*{\subsection}{\Large\color{orange}\headingfont}
\titleformat*{\subsubsection}{\large\color{orange}\headingfont}
\renewcommand{\maketitlehooka}{\headingfont}

\begin{document}

% To inlcude background wallpaper/image
%\CenterWallPaper{1}{TKML_ESB_Page_Background_2}

%\layout    

% FRONTMATTER STARTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\frontmatter

\tableofcontents
\clearpage

\addcontentsline{toc}{section}{\listtablename}
\listoftables
\clearpage

\onecolumn
\thispagestyle{plain} % To not have "List of Tables appear" at the top of the "Preface" page
\section{Preface}
\blindtext
\clearpage

\thispagestyle{plain} % To not have "List of Tables appear" at the top of the "Preface" page
\section{Introduction}
\blindtext
\twocolumn

\clearpage

% MAINMATTER STARTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\mainmatter

\blindtext

\end{document}

内容 劳伦斯

答案1

您的代码中存在几个问题:

  1. 你加载了很多包,我猜你并不需要。在下面的 MWE 中,我减少了加载的包,使之更加精简。如果包中有注释,请阅读注释,解释我这样做的原因。
  2. 因为您正在加载包,所以我添加了使用字体 Chandara 作为文档的fontspec命令。\setmainfont[Scale=1.0]{Candara}
  3. 因为您已经在使用包,所以tocloft您可以使用以下几行来操作 TOC 和 LOF 中使用的代码和颜色:

    \renewcommand{\cfttoctitlefont}{\Huge\color{green}\headingfont} % tocloft
    \renewcommand{\cftloftitlefont}{\Huge\color{green}\headingfont} % tocloft
    \renewcommand{\cftchapfont}{\color{green}\headingfont} % tocloft
    \renewcommand{\cftsecfont}{\color{green}\headingfont} % tocloft
    \renewcommand{\cftsubsecfont}{\color{green}\headingfont} % tocloft
    \renewcommand{\cftchappagefont}{\color{green}\headingfont} % tocloft
    
  4. \Blinddocument我使用包中的命令blindtext为完整文档生成虚拟文本......

使用以下完整的 MWE(请参阅标有 ​​的重要代码更改<======):

\documentclass[oneside,centered,twocolumn]{book}

\special{papersize=215.9mm,279.4mm}
\usepackage[english]{babel}

\usepackage[demo]{graphicx}

\usepackage{tocloft} % Customization of TOC LOF LOT <===================
\usepackage[table,xcdraw]{xcolor} % For shading in tables
%\usepackage{pdfcolmk} % <==== not needed with xelatex
\usepackage{multirow}

\usepackage{blindtext}
%\usepackage{showframe}

\usepackage{caption} % To change way captions are labelled
\usepackage{scrextend}

\usepackage{titlesec}

\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{titling}
\usepackage{fontspec}
\setmainfont[Scale=1.0]{Candara} % <====================================

\usepackage{fancyhdr}

% To make TOC in two columns and List of Tables into one column.
\usepackage{multitoc}
\makeatletter
\renewcommand*{\@starttoc}[1]{%
    \ifthenelse{\equal{#1}{toc}}{%
        \ifnum\multicolumntoc>1
        \begin{multicols}{\multicolumntoc}%
            \@multitoc@starttoc{#1}%
        \end{multicols}%
        \else
        \@multitoc@starttoc{#1}%
        \fi}{}%
    \ifthenelse{\equal{#1}{lot}}{%
        \ifnum\multicolumnlot>1
        \begin{multicols}{\multicolumnlot}%
            \@multitoc@starttoc{#1}%
        \end{multicols}%
        \else
        \@multitoc@starttoc{#1}%
        \fi}{}%
    \ifthenelse{\equal{#1}{lof}}{%
        \ifnum\multicolumnlof>1
        \begin{multicols}{\multicolumnlof}%
            \@multitoc@starttoc{#1}%
        \end{multicols}%
        \else
        \@multitoc@starttoc{#1}%
        \fi}{}%
}
\makeatother
\renewcommand{\multicolumnlot}{1}


% CHAPTER, SECTION, SUBSECTION STYLE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newfontfamily\headingfont[]{Candara}
\titleformat{\chapter}[display]
{\bfseries\color{blue}\filcenter\fontsize{35}{35}\headingfont} % Size of Chapter1&Chapter
{\huge\MakeUppercase\headingfont{\chaptertitlename} \thechapter}
{12pt}
{\tikz[remember picture,overlay]\node[inner sep=0pt] at ($(current page.north) +
    (0pt,-117pt)$) {\includegraphics[width=14cm]{chapterHead_10cm}};}

\titlespacing{\chapter}{0pt}{50mm}{42.5mm}
\titleformat*{\section}{\LARGE\color{orange}\headingfont}
\titleformat*{\subsection}{\Large\color{orange}\headingfont}
\titleformat*{\subsubsection}{\large\color{orange}\headingfont}
\renewcommand{\maketitlehooka}{\headingfont}

\renewcommand{\cfttoctitlefont}{\Huge\color{green}\headingfont} % tocloft <=====
\renewcommand{\cftloftitlefont}{\Huge\color{green}\headingfont} % tocloft <=====
\renewcommand{\cftchapfont}{\color{green}\headingfont} % tocloft <==============
\renewcommand{\cftsecfont}{\color{green}\headingfont} % tocloft <===============
\renewcommand{\cftsubsecfont}{\color{green}\headingfont} % tocloft <============
\renewcommand{\cftchappagefont}{\color{green}\headingfont} % tocloft <==========


\begin{document}

\tableofcontents
\listoffigures
\Blinddocument % <======================================================
\end{document}

您将获得以下结果:

目录

如您所见,目录标题的字体和颜色发生了变化,目录中章节、节和小节的颜色也发生了变化。\cftchappagefont更改了目录中章节的页码,您可以\cftsecpagefont对章节等使用类似的更改。

答案2

在此处输入图片描述

将命令\cfttoctitlefont\cftfigfont和更新\cftlottitlefont为您想要的任何字体样式。

为了提高可读性,我删除了不必要的代码。

\documentclass[oneside,centered,twocolumn]{book}

\usepackage[T1]{fontenc}
\usepackage{fontspec}
\usepackage{xcolor}
\usepackage{blindtext}
\usepackage{tocloft}
\usepackage[]{tocbibind} % use this package to automatically insert list of tables and list of figures into the TOC

\newfontfamily\headingfont[]{Candara}
\newcommand{\toctitlefont}{\Huge \color{orange} \headingfont \bfseries} % font of the titles of lists (e.g., List of Tables)

% Change font style for TOC, LOT, and LOF here
    \renewcommand{\cfttoctitlefont}{\toctitlefont}
    \renewcommand{\cftfigfont}{\tocsecpagefont} 
    \renewcommand{\cftlottitlefont}{\toctitlefont}




\begin{document}

% To inlcude background wallpaper/image
%\CenterWallPaper{1}{TKML_ESB_Page_Background_2}

%\layout    

% FRONTMATTER STARTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\frontmatter

\tableofcontents
\clearpage

%\addcontentsline{toc}{section}{\listtablename} use tocbibind package and remove this
\listoftables
\clearpage

\listoffigures
\clearpage


\onecolumn
\thispagestyle{plain} % To not have "List of Tables appear" at the top of the "Preface" page
\section{Preface}
\blindtext
\clearpage

\thispagestyle{plain} % To not have "List of Tables appear" at the top of the "Preface" page
\section{Introduction}
\blindtext
\twocolumn

\clearpage

% MAINMATTER STARTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\mainmatter

\blindtext

\end{document}

无关:使用tocbibind包来更好地处理表格列表、图片列表和索引。默认情况下,它会自动将其位置插入到目录中。它还提供简单的选项,如、,nottoc以确定是否将目录、表格列表和图片列表插入到目录中notlotnotlof

相关内容