\fancyhead 偶数页与奇数页失败

\fancyhead 偶数页与奇数页失败

我正在创建工作表,其中奇数页的标题应为“练习”,而偶数页的标题应为“解决方案”,使用 documentclassarticle进行双面打印。

为什么此代码会让所有页面的页眉都显示“练习奇数页”?

\documentclass[twosided]{article}

\usepackage{fancyhdr}
 \pagestyle{fancy}
 \fancyhead[CO]{\Large Odd Pages for Exercises}
 \fancyhead[CE]{\Large Even Pages for Solutions}

\begin{document}

should be odd and say so in header

\newpage

should be even and say so in header

\newpage

should be odd and say so in header

\newpage

should be even and say so in header

\end{document}

答案1

您的问题非常简单:您必须使用的类选项是twoside您使用的twosided。另请参阅您收到的日志文件中的警告!

因此使用正确的代码

\documentclass[twoside]{article} % <====================================

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[CO]{\Large Odd Pages for Exercises}
\fancyhead[CE]{\Large Even Pages for Solutions}


\begin{document}

should be odd and say so in header page 1

\newpage

should be even and say so in header page 2

\newpage

should be odd and say so in header page 3

\newpage

should be even and say so in header page 4

\end{document}

你得到了想要的结果:

结果

答案2

这应该可以做到:

\documentclass[twoside]{article}

\usepackage{fancyhdr}
\fancypagestyle{somepagestyle}{
\fancyhead[CO]{\Large Odd Pages for Exercises}
\fancyhead[CE]{\Large Even Pages for Solutions}}
\pagestyle{somepagestyle}

\begin{document}

should be odd and say so in header

\newpage

should be even and say so in header

\newpage

should be odd and say so in header

\newpage

should be even and say so in header

\end{document}

顺便说一句,课程选项是twoside,而不是twosided

相关内容