在下面的 MWE 中,我无法更改“算法列表”页面的目录的字体(和格式)。如您所见,目录的字体是\sffamily
,但是,当我尝试对算法页面进行相同的格式化时,没有任何反应。您能帮我格式化算法列表目录页面以匹配其他目录页面吗?
以下是 MWE:
\documentclass{book}
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,letterpaper]{geometry}
\usepackage{graphicx}
\usepackage{tikz} % Required for drawing custom shapes
\usepackage[english]{babel} % English language/hyphenation
\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{52,177,201}
\definecolor{mybluei}{RGB}{0,173,239}
\usepackage{lipsum}
\usepackage{amsmath,amsfonts,amssymb,amsthm, bm} % For math equations, theorems, symbols, etc
\usepackage[explicit,calcwidth]{titlesec}
\usepackage{titletoc} % Required for manipulating the table of contents
\contentsmargin{0cm} % Removes the default margin
% Chapter text styling
\titlecontents{chapter}[1.25cm] % Indentation
{\addvspace{12pt}\large\sffamily\bfseries} % Spacing and font options for chapters
{\color{ocre!60}\contentslabel[\Large\thecontentslabel]{1.25cm}\color{ocre}} % Chapter number
{\color{ocre}}
{\color{ocre!60}\normalsize\;\titlerule*[.5pc]{.}\;\thecontentspage} % Page number
% Section text styling
\titlecontents{section}[1.25cm] % Indentation
{\addvspace{3pt}\sffamily\bfseries} % Spacing and font options for sections
{\contentslabel[\thecontentslabel]{1.25cm}} % Section number
{}
{\hfill\color{black}\thecontentspage} % Page number
[]
% Subsection text styling
\titlecontents{subsection}[1.25cm] % Indentation
{\addvspace{1pt}\sffamily\small} % Spacing and font options for subsections
{\contentslabel[\thecontentslabel]{1.25cm}} % Subsection number
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage} % Page number
[]
% List of figures
\titlecontents{figure}[0em]
{\addvspace{5pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]
% List of tables
\titlecontents{table}[0em]
{\addvspace{-5pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]
% List of listings
\contentsuse{lstlisting}{lol}
\titlecontents{lstlisting}[0em]
{\addvspace{5pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]
% List of Algorithms
\contentsuse{algorithms}{lol}
\titlecontents{algorithms}[0em]
{\addvspace{5pt}\large\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\newcommand\mycommfont[1]{\footnotesize\ttfamily\textcolor{blue}{#1}}
\SetCommentSty{mycommfont}
\begin{document}
\pagestyle{empty}
\tableofcontents
\listoffigures
\listofalgorithms
\chapter{Problem}
\lipsum[1]
\section{Problem Statement 1}
\lipsum[1]
\begin{figure}[!h]
\caption{This is a description for Figure 1}
\includegraphics[width=0.6\columnwidth]{example-image-c}
\end{figure}
\begin{figure}[!h]
\caption{This is a description for Figure 2}
\includegraphics[width=0.6\columnwidth]{example-image-c}
\end{figure}
\chapter{List of Matlab Algorithms}
\section{Algorithm 1}
\begin{algorithm}[H]
some text here
\caption{Principal Component Analysis (PCA) Training}
\end{algorithm}
\begin{algorithm}[H]
some text here
\caption{Principal Component Analysis (PCA) Training 2}
\end{algorithm}
\begin{algorithm}[H]
some text here
\caption{Principal Component Analysis (PCA) Training 3}
\end{algorithm}
\lipsum[1]
\appendix
\chapter{References}
\end{document}
答案1
你必须使用
\titlecontents{algocf}
因为该包algorithm2e
将字幕存储为
\contentsline{algocf}{...}
在.loa
文件中。但是,这个包似乎不想合作,titletoc
无法初始化它的一个变量,所以我们需要提供一些帮助。
\documentclass{book}
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,letterpaper]{geometry}
\usepackage[english]{babel} % English language/hyphenation
\usepackage{amsmath,amsfonts,amssymb,amsthm, bm} % For math equations, theorems, symbols, etc
\usepackage{graphicx}
\usepackage{tikz} % Required for drawing custom shapes
\usepackage{xcolor} % Required for specifying colors by name
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\usepackage[explicit,calcwidth]{titlesec}
\usepackage{titletoc} % Required for manipulating the table of contents
\usepackage{lipsum}
\definecolor{ocre}{RGB}{52,177,201}
\definecolor{mybluei}{RGB}{0,173,239}
\contentsmargin{0cm} % Removes the default margin
% Chapter text styling
\titlecontents{chapter}[1.25cm] % Indentation
{\addvspace{12pt}\large\sffamily\bfseries} % Spacing and font options for chapters
{\color{ocre!60}\contentslabel[\Large\thecontentslabel]{1.25cm}\color{ocre}} % Chapter number
{\color{ocre}}
{\color{ocre!60}\normalsize\;\titlerule*[.5pc]{.}\;\thecontentspage} % Page number
% Section text styling
\titlecontents{section}[1.25cm] % Indentation
{\addvspace{3pt}\sffamily\bfseries} % Spacing and font options for sections
{\contentslabel[\thecontentslabel]{1.25cm}} % Section number
{}
{\hfill\color{black}\thecontentspage} % Page number
[]
% Subsection text styling
\titlecontents{subsection}[1.25cm] % Indentation
{\addvspace{1pt}\sffamily\small} % Spacing and font options for subsections
{\contentslabel[\thecontentslabel]{1.25cm}} % Subsection number
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage} % Page number
[]
% List of figures
\titlecontents{figure}[0em]
{\addvspace{5pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]
% List of tables
\titlecontents{table}[0em]
{\addvspace{-5pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]
% List of listings
\contentsuse{lstlisting}{lol}
\titlecontents{lstlisting}[0em]
{\addvspace{5pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]
% List of Algorithms
\contentsuse{algorithms}{lol}
\titlecontents{algocf}[0em]
{\addvspace{5pt}\sffamily}
{\thecontentslabel\hspace*{1em}}
{}
{\ \titlerule*[.5pc]{.}\;\thecontentspage}
[]
\newcommand\mycommfont[1]{\footnotesize\ttfamily\textcolor{blue}{#1}}
\SetCommentSty{mycommfont}
\makeatletter
% for some reasons, \ttll@algocf is not initialized
\AtBeginDocument{\providecommand\ttll@algocf{-1000}}
\makeatother
\begin{document}
\pagestyle{empty}
\tableofcontents
\listoffigures
\listofalgorithms
\chapter{Problem}
\lipsum[1]
\section{Problem Statement 1}
\lipsum[1]
\begin{figure}[!htp]
\caption{This is a description for Figure 1}
\includegraphics[width=0.6\columnwidth]{example-image-c}
\end{figure}
\begin{figure}[!htp]
\caption{This is a description for Figure 2}
\includegraphics[width=0.6\columnwidth]{example-image-c}
\end{figure}
\chapter{List of Matlab Algorithms}
\section{Algorithm 1}
\begin{algorithm}[H]
some text here
\caption{Principal Component Analysis (PCA) Training}
\end{algorithm}
\begin{algorithm}[H]
some text here
\caption{Principal Component Analysis (PCA) Training 2}
\end{algorithm}
\begin{algorithm}[H]
some text here
\caption{Principal Component Analysis (PCA) Training 3}
\end{algorithm}
\lipsum[1]
\appendix
\chapter{References}
\end{document}