这个问题源于解决方案在这里找到。
根据给出的解决方案埃格尔,我仍然无法编译我的代码。
请帮我编译以下代码,以便我可以控制算法目录列表来更改其字体等。
当我运行此代码时,出现错误:
LaTeX Error: Command \l@algocf already defined. Or name \end... illegal,...
l.2476 ...l@algocf{\@dottedtocline{1}{1em}{2.3em}} % line of the list ?
这是我目前的代码:
\documentclass{book}
\usepackage{todonotes}
\usepackage{calc}
\usepackage{amsmath,amsfonts,amssymb,amsthm, bm}
\usepackage{graphicx}
\definecolor{lightblue}{RGB}{199,232,250}
\definecolor{darkblue}{RGB}{59,134,215}
%======================================================================================
% MAIN TABLE OF CONTENTS
%======================================================================================
\usepackage{titletoc} % Required for manipulating the table of contents
\contentsmargin{0cm} % Removes the default margin
% Part text styling
\titlecontents{part}[0cm]
{\addvspace{20pt}\centering\large\bfseries}
{}
{}
{}
% Chapter text styling
\titlecontents{chapter}[1.25cm] % Indentation
{\addvspace{12pt}\large\sffamily\bfseries} % Spacing and font options for chapters
{\color{darkblue!60}\contentslabel[\Large\thecontentslabel]{1.25cm}\color{darkblue}} % Chapter number
{\color{darkblue}}
{\color{darkblue!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}
[]
\makeatletter
% for some reasons, \ttll@algocf is not initialized
\AtBeginDocument{\providecommand\ttll@algocf{-1000}}
\makeatother
%======================================================================================
% ALGORITHM
%======================================================================================
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\usepackage{float}
\definecolor{mybluei}{RGB}{0,173,239}
\renewcommand{\listalgorithmcfname}{List of Algorithms}
\newcommand\mycommfont[1]{\footnotesize\ttfamily\textcolor{blue}{#1}}
\SetCommentSty{mycommfont}
\makeatletter
\newcommand{\nosemic}{\renewcommand{\@endalgocfline}{\relax}}% Drop semi-colon ;
\newcommand{\dosemic}{\renewcommand{\@endalgocfline}{\algocf@endline}}% Reinstate semi-colon ;
\newcommand{\pushline}{\Indp}% Indent
\newcommand{\popline}{\Indm\dosemic}% Undent
\let\oldnl\nl% Store \nl in \oldnl
\newcommand{\nonl}{\renewcommand{\nl}{\let\nl\oldnl}}% Remove line number for one line
\let\@@thealgoline\theAlgoLine
\newif\ifuseothernumbering
\newcounter{SubAlgoLine}
\renewcommand{\theSubAlgoLine}{\@@thealgoline\alph{SubAlgoLine}}
\renewcommand{\theAlgoLine}{%
\ifuseothernumbering
\ifnum\c@AlgoLine=3
\protect\refstepcounter{SubAlgoLine}
\theSubAlgoLine%
\else
\ifnum\c@AlgoLine=4
\protect\refstepcounter{SubAlgoLine}
\addtocounter{AlgoLine}{\m@ne}%
\theSubAlgoLine%
\global\useothernumberingfalse
\else
\@@thealgoline%
\fi
\fi
\else
\@@thealgoline%
\fi
}
\makeatother
\renewcommand\AlCapFnt{\bfseries\color{darkblue}}
\renewcommand\AlCapNameFnt{\bfseries\itshape\color{darkblue}}
\newcommand\bigzero{\makebox(0,0){\text{\huge0}}}
\begin{document}
%========================================================================================
% TABLE OF CONTENTS
%========================================================================================
\tableofcontents
\listoffigures
\listofalgorithms
\chapter{Algorithms}
\colorbox{green!05}{\color{black}
\begin{minipage}{\textwidth}
\begin{algorithm}[H]
\setcounter{AlgoLine}{8}
\SetAlgoLined
\SetNlSty{textbf}{}{:}
Normalization of eigenfaces
\begin{equation*}
E_{n} = E_{s}\begin{bmatrix}
\frac{1}{\sqrt{\lambda}_{1}} & & & \\
& \frac{1}{\sqrt{\lambda}_{2}} & &\bigzero \\
\bigzero & & \ddots & \\
& & & \frac{1}{\sqrt{\lambda}_{M-1}}\\
\end{bmatrix}
\end{equation*}\\
\caption{Principal Component Analysis (PCA) Training }
\end{algorithm}
\end{minipage}}
\colorbox{green!05}{\color{black}
\begin{minipage}{\textwidth}
\begin{algorithm}[H]
\setcounter{AlgoLine}{8}
\SetAlgoLined
\SetNlSty{textbf}{}{:}
Normalization of eigenfaces
\begin{equation*}
E_{n} = E_{s}\begin{bmatrix}
\frac{1}{\sqrt{\lambda}_{1}} & & & \\
& \frac{1}{\sqrt{\lambda}_{2}} & &\bigzero \\
\bigzero & & \ddots & \\
& & & \frac{1}{\sqrt{\lambda}_{M-1}}\\
\end{bmatrix}
\end{equation*}\\
\caption{Principal Component Analysis (PCA) Training }
\end{algorithm}
\end{minipage}}
\begin{figure}
\centering
\includegraphics[width=3cm]{example-image-a}
\caption{Principal Component Analysis (PCA) Training }
\end{figure}
\begin{figure}
\centering
\includegraphics[width=3cm]{example-image-a}
\caption{Principal Component Analysis (PCA) Training }
\end{figure}
\begin{figure}
\centering
\includegraphics[width=3cm]{example-image-a}
\caption{Principal Component Analysis (PCA) Training }
\end{figure}
\end{document}
答案1
在开始更改设置之前,请加载所有包。
\documentclass{book}
\usepackage{todonotes}
\usepackage{calc}
\usepackage{amsmath,amsfonts,amssymb,amsthm, bm}
\usepackage{graphicx}
\usepackage{titletoc} % Required for manipulating the table of contents
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\usepackage{float}
\definecolor{lightblue}{RGB}{199,232,250}
\definecolor{darkblue}{RGB}{59,134,215}
%======================================================================================
% MAIN TABLE OF CONTENTS
%======================================================================================
\contentsmargin{0cm} % Removes the default margin
% Part text styling
\titlecontents{part}[0cm]
{\addvspace{20pt}\centering\large\bfseries}
{}
{}
{}
% Chapter text styling
\titlecontents{chapter}[1.25cm] % Indentation
{\addvspace{12pt}\large\sffamily\bfseries} % Spacing and font options for chapters
{\color{darkblue!60}\contentslabel[\Large\thecontentslabel]{1.25cm}\color{darkblue}} % Chapter number
{\color{darkblue}}
{\color{darkblue!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}
[]
\makeatletter
% for some reasons, \ttll@algocf is not initialized
\AtBeginDocument{\providecommand\ttll@algocf{-1000}}
\makeatother
%======================================================================================
% ALGORITHM
%======================================================================================
\definecolor{mybluei}{RGB}{0,173,239}
\renewcommand{\listalgorithmcfname}{List of Algorithms}
\newcommand\mycommfont[1]{\footnotesize\ttfamily\textcolor{blue}{#1}}
\SetCommentSty{mycommfont}
\makeatletter
\newcommand{\nosemic}{\renewcommand{\@endalgocfline}{\relax}}% Drop semi-colon ;
\newcommand{\dosemic}{\renewcommand{\@endalgocfline}{\algocf@endline}}% Reinstate semi-colon ;
\newcommand{\pushline}{\Indp}% Indent
\newcommand{\popline}{\Indm\dosemic}% Undent
\let\oldnl\nl% Store \nl in \oldnl
\newcommand{\nonl}{\renewcommand{\nl}{\let\nl\oldnl}}% Remove line number for one line
\let\@@thealgoline\theAlgoLine
\newif\ifuseothernumbering
\newcounter{SubAlgoLine}
\renewcommand{\theSubAlgoLine}{\@@thealgoline\alph{SubAlgoLine}}
\renewcommand{\theAlgoLine}{%
\ifuseothernumbering
\ifnum\c@AlgoLine=3
\protect\refstepcounter{SubAlgoLine}
\theSubAlgoLine%
\else
\ifnum\c@AlgoLine=4
\protect\refstepcounter{SubAlgoLine}
\addtocounter{AlgoLine}{\m@ne}%
\theSubAlgoLine%
\global\useothernumberingfalse
\else
\@@thealgoline%
\fi
\fi
\else
\@@thealgoline%
\fi
}
\makeatother
\renewcommand\AlCapFnt{\bfseries\color{darkblue}}
\renewcommand\AlCapNameFnt{\bfseries\itshape\color{darkblue}}
\newcommand\bigzero{\makebox(0,0){\text{\huge0}}}
\begin{document}
%========================================================================================
% TABLE OF CONTENTS
%========================================================================================
\tableofcontents
\listoffigures
\listofalgorithms
\chapter{Algorithms}
\colorbox{green!05}{\color{black}
\begin{minipage}{\textwidth}
\begin{algorithm}[H]
\setcounter{AlgoLine}{8}
\SetAlgoLined
\SetNlSty{textbf}{}{:}
Normalization of eigenfaces
\begin{equation*}
E_{n} = E_{s}\begin{bmatrix}
\frac{1}{\sqrt{\lambda}_{1}} & & & \\
& \frac{1}{\sqrt{\lambda}_{2}} & &\bigzero \\
\bigzero & & \ddots & \\
& & & \frac{1}{\sqrt{\lambda}_{M-1}}\\
\end{bmatrix}
\end{equation*}\\
\caption{Principal Component Analysis (PCA) Training }
\end{algorithm}
\end{minipage}}
\colorbox{green!05}{\color{black}
\begin{minipage}{\textwidth}
\begin{algorithm}[H]
\setcounter{AlgoLine}{8}
\SetAlgoLined
\SetNlSty{textbf}{}{:}
Normalization of eigenfaces
\begin{equation*}
E_{n} = E_{s}\begin{bmatrix}
\frac{1}{\sqrt{\lambda}_{1}} & & & \\
& \frac{1}{\sqrt{\lambda}_{2}} & &\bigzero \\
\bigzero & & \ddots & \\
& & & \frac{1}{\sqrt{\lambda}_{M-1}}\\
\end{bmatrix}
\end{equation*}\\
\caption{Principal Component Analysis (PCA) Training }
\end{algorithm}
\end{minipage}}
\begin{figure}
\centering
\includegraphics[width=3cm]{example-image-a}
\caption{Principal Component Analysis (PCA) Training }
\end{figure}
\begin{figure}
\centering
\includegraphics[width=3cm]{example-image-a}
\caption{Principal Component Analysis (PCA) Training }
\end{figure}
\begin{figure}
\centering
\includegraphics[width=3cm]{example-image-a}
\caption{Principal Component Analysis (PCA) Training }
\end{figure}
\end{document}