\@fancyhead 在 Tex Live 2017 中未定义

\@fancyhead 在 Tex Live 2017 中未定义

以下代码来自当没有标题时自动删除标尺在 Tex Live 2016 中编译良好:

\documentclass{article}
\usepackage{fancyhdr}
    \makeatletter
    \let\org@fancyhead\@fancyhead
    \renewcommand*{\@fancyhead}[5]{\sbox0{#2#3#4}\ifdim\wd0=\z@ \let\headrule\relax \fi \org@fancyhead{#1}{#2}{#3}{#4}{#5}} % remove ruler if header is empty
    \makeatother

\begin{document}
Foo
\end{document}

但在 Tex Live 2017 中,它给出了错误LaTeX Error: \@fancyhead undefined。为什么?我该如何解决这个问题?

答案1

由于更改历史记录中未记录的原因, 中的许多内部宏fancyhdr都已更改名称。这是依赖于修改此类内部宏的代码而不是修改面向用户的宏的危险之一。在此特定情况下,\@fancyhead现在是\f@nch@head。因此以下代码有效:

\documentclass{article}
\usepackage{lipsum}
\usepackage{fancyhdr}
\makeatletter
\let\org@fancyhead\f@nch@head
\renewcommand*{\f@nch@head}[5]{\sbox0{#2#3#4}\ifdim\wd0=\z@ \let\headrule\relax \fi \org@fancyhead{#1}{#2}{#3}{#4}{#5}} % remove ruler if header is empty
\makeatother
\pagestyle{fancy}
\fancyhead{}
\begin{document}
\section{My first section}
\lipsum
\newpage
\fancyhead[C]{Header is set}
\section{My next section}
\lipsum
\end{document}

相关内容