當我自訂\contentsname
with時,我發現or\renewcommand
的存在會導致編譯失敗。我無法理解這一點。為什麼?這是包的問題還是包的問題?\pagestyle{fancy}
\thispagestyle{fancy}
\contentsname
fancyhdr
微量元素:
\documentclass{article}
\usepackage{geometry,fancyhdr}
\geometry{showframe}
\begin{document}
\pagestyle{fancy}% This command leads to un-compiled. If this command is commented, or replaced by\pagestyle{plain}, everyting is all right.
\renewcommand\contentsname{%
\LARGE%
\centering%
my\\ content%
}
\tableofcontents
\section{section}
text
\end{document}
PS:我發現與位置相關的宏,如\centering
,\\
是失敗的原因。其他與位置無關的宏,如\color
,\Large
不影響 \renewcommand\contentsname。
答案1
\documentclass{article}
\usepackage{geometry,fancyhdr,titlesec,xcolor}
\geometry{showframe}
\begin{document}
\pagestyle{fancy}% This command leads to un-compiled. If this command is commented, or replaced by\pagestyle{plain}, everyting is all right.
\renewcommand\contentsname{%
My \\ content%
}
{
\titleformat*{\section}{\vspace*{-0.5\baselineskip}\centering \LARGE\color{red}}
\tableofcontents
}
\section{section}
text
\end{document}