内容标题居中问题

内容标题居中问题

我有时会遇到致命错误

TeX capacity exceeded, sorry [input stack size=5000].

\reserved@a ->\def \reserved@a 
            *{\ttl@assign@i {\@tempskipb }}\reserved@a 
l.10 \tableofcontents
                     
If you really absolutely need more capacity,
you can ask a wizard to enlarge me.

当我将\renewcommand{\contentsname}{\centering Contents}目录标题放在中间时,我不知道为什么,但对于某些文档,它有效,而对于其他文档,它无效。序言几乎相同。有人知道为什么它有时不起作用,以及我该如何修复它吗?

例如,下面是一份文档,没有工作:

\documentclass[11pt,a4paper]{article}                       % 10pt default. Article = \subsubsection numbered, no \chapter, notitlepage

%%% Packages - always used 
\usepackage[utf8]{inputenc}                                 % Overleaf's default file encoding
\usepackage{amsmath, amssymb, amsthm}                       % AMS standards
\usepackage[margin=1in]{geometry}                           % Set margins (use "=1.5cm" to make smaller)
\usepackage[compact]{titlesec}                              % Reduce space below section titles (and allow title format editing)
\allowdisplaybreaks                                         % Allow multiline equations to span pages
\interfootnotelinepenalty=10000                             % Ensure footnotes don't span pages

%%% Packages - toggle usage
\usepackage{hyperref}                                       % Hyperlinks
\usepackage{cleveref}                                       % Clever references
\newcommand{\crefrangeconjunction}{--}                      % '-' for range of references
\renewcommand{\contentsname}{\centering Contents}           % Contents title centred
\usepackage{tikz}                                           % Tikz pictures
\graphicspath{{images/}}                                    % Set image folder
\usepackage{subfig}                                         % Use "\subfloat[]{}" for sub-figures
\usepackage[format=hang,font=small,labelfont=bf]{caption}   % Caption set-up
\usepackage{rotating}                                       % "sidewaysfigure" and "sidewaystable" environments
\usepackage{float}                                          % "H" float specifier
%\usepackage{showlabels}                                     % Show labels

%%% Title
\title{Measuring the Behaviour of Submerged Jets}
\author{Jonathan Bolton}

%%% Headers & Footers
\usepackage{fancyhdr}
\pagestyle{fancy}
\setlength{\headheight}{13.6pt}
\fancyhf{}
\lhead{Lab Report}
\chead{MATH5453: Foundations of Fluid Dynamics}
\rhead{Jonathan Bolton}
\lfoot{}
\cfoot{\thepage}
\rfoot{}

%%% Bibliography
\usepackage[style=numeric-comp,sorting=none,sortcites=false,maxbibnames=99,maxcitenames=2]{biblatex}
\addbibresource{bib.bib}
\DeclareFieldFormat[article]{title}{#1}                         % Remove " from article title
\DeclareFieldFormat{url}{Available from\addcolon\space\url{#1}} % Add "available from:" to url
\renewbibmacro{in:}{}                                           % Remove "in"
\renewbibmacro{volume+number+eid}{%                             % Change volume/number syntax
    \textbf{\printfield{volume}}\printfield[parens]{number}\setunit{\addcomma\space}\printfield{eid}}

%%% SI setup
\usepackage{siunitx}
\sisetup{range-phrase=-}

\begin{document}
\maketitle
\tableofcontents
\noindent\hrulefill
\newpage
%========================
\section{Test}
%========================

%========================
\newpage
\printbibliography[heading=bibintoc]
%========================
\end{document}

这是一份文件,它工作

\documentclass[11pt,a4paper]{article}                       % 10pt default. Article = \subsubsection numbered, no \chapter, notitlepage

%%% Packages - always used 
\usepackage[utf8]{inputenc}                                 % Overleaf's default file encoding
\usepackage{amsmath, amssymb, amsthm}                       % AMS standards
\usepackage[margin=1in]{geometry}                           % Set margins (use "=1.5cm" to make smaller)
\usepackage[compact]{titlesec}                              % Reduce space below section titles (and allow title format editing)
\allowdisplaybreaks                                         % Allow multiline equations to span pages
\interfootnotelinepenalty=10000                             % Ensure footnotes don't span pages

%%% Packages - toggle usage
\usepackage{hyperref}                                       % Hyperlinks
\usepackage{cleveref}                                       % Clever references
\newcommand{\crefrangeconjunction}{--}                      % '-' for range of references
\renewcommand{\contentsname}{\centering Contents}           % Contents title centred
\usepackage{tikz}                                           % Tikz pictures
\usetikzlibrary{patterns}
\graphicspath{{images/}}                                    % Set image folder
\usepackage{subfig}                                         % Use "\subfloat[]{}" for sub-figures
\usepackage[format=hang,font=small,labelfont=bf]{caption}   % Caption set-up
\usepackage{multicol}                                       % "multicols" environment 
%\usepackage{showlabels}                                     % Show labels

%%% Title
\title{The Immersed Boundary Method for Fluid-Structure Interaction Problems}
\author{Me}

%%% Headers & Footers
\usepackage{fancyhdr}
\pagestyle{fancy}
\setlength{\headheight}{13.6pt}
\fancyhf{}
\lhead{Literature Review}
\chead{COMP5454M: Fluid-Structure Interactions}
\rhead{Me}
\lfoot{}
\cfoot{\thepage}
\rfoot{}

%%% 'Closed' sqrt symbol
\usepackage{letltxmacro}
\makeatletter
\let\oldr@@t\r@@t
\def\r@@t#1#2{%
\setbox0=\hbox{$\oldr@@t#1{#2\,}$}\dimen0=\ht0
\advance\dimen0-0.2\ht0
\setbox2=\hbox{\vrule height\ht0 depth -\dimen0}%
{\box0\lower0.4pt\box2}}
\LetLtxMacro{\oldsqrt}{\sqrt}
\renewcommand*{\sqrt}[2][\ ]{\oldsqrt[#1]{#2}}
\makeatother

%%% Bibliography
\usepackage[style=numeric-comp,sorting=none,sortcites=false,maxbibnames=99,maxcitenames=2]{biblatex}
\addbibresource{bib.bib}
\DeclareFieldFormat[article]{title}{#1}                         % Remove " from article title
\DeclareFieldFormat{url}{Available from\addcolon\space\url{#1}} % Add "available from:" to url
\renewbibmacro{in:}{}                                           % Remove "in"
\renewbibmacro{volume+number+eid}{%                             % Change volume/number syntax
    \textbf{\printfield{volume}}\printfield[parens]{number}\setunit{\addcomma\space}\printfield{eid}}

%%% New commands
\newcommand{\dd}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\mtext}[1]{\enspace\text{#1}\enspace}

\begin{document}
\maketitle
\tableofcontents
\noindent\hrulefill
\newpage
%========================
\section{Test}
%========================

%========================
\newpage
\printbibliography[heading=bibintoc]
%========================
\end{document}

相关内容