当我自定义\contentsname
with时\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}