[Tex/LaTex] How to set custom fancy pagestyle back to default fancy

fancyhdrheader-footer

I am using a custom fancy pagestyle for my acronyms pages and I am wondering how I set the pagestyle back to "default" for the rest of my document. This is my example:

\documentclass[11pt, twoside, a4paper, DIV12, BCOR16mm, listof=totoc ]{scrartcl}
\usepackage{fancyhdr}
\usepackge{acronym}
\fancypagestyle{acronyms}{
  \fancyhf{}
  \fancyhead[LO]{Acronyms}
  \fancyhead[RE]{Acronyms}
  \cfoot{\thepage}
}
\begin{document}
  \pagestyle{acronyms}
\section{Acronyms}
  \begin{acronym}
    \acro{BLA}{BLA}
  \end{acronym}
  \newpage
  \pagestyle{fancy}
\section{Section 2}
Some Text....
\end{document}

The effect is that the pagestyle is still set to \pagestyle{acronyms} and not set back to "default".
I also used \thispagestyle{acronyms} but since my acronyms are more than one page this doesn't work anymore.

Best Answer

Note that with a KOMA-Script class the usage of scrlayer-scrpage is recommended:

\documentclass[11pt, twoside, a4paper, DIV=12, BCOR=16mm, listof=totoc]{scrartcl}
\usepackage[
  automark,
  headsepline,
  markcase=upper
]{scrlayer-scrpage}
\clearpairofpagestyles
\ihead{\leftmark}
\ohead{\rightmark}
\cfoot*{\pagemark}

\usepackage{acronym}
\newpairofpagestyles[scrheadings]{acronyms}{%
  \ihead{}\ohead{Acronyms}}

\usepackage{blindtext}
\begin{document}
\pagestyle{acronyms}
\section{Acronyms}
  \begin{acronym}
    \acro{BLA}{BLA}
  \end{acronym}
  \clearpage
  \pagestyle{scrheadings}
  \blinddocument
\end{document}

It is also possible to use fancyhdr. Then you have to define another page style:

\documentclass[11pt, twoside, a4paper, DIV=12, BCOR=16mm, listof=totoc]{scrartcl}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancypagestyle{main}{
\fancyhf{}
\fancyhead[LE,RO]{\slshape \rightmark}
\fancyhead[LO,RE]{\slshape \leftmark}
\fancyfoot[C]{\thepage}
\renewcommand*{\headrulewidth}{0.4pt}
\renewcommand*{\footrulewidth}{0pt}
}

\usepackage{acronym}
\fancypagestyle{acronyms}{
  \fancyhf{}
  \fancyhead[LO,RE]{Acronyms}
  \cfoot{\thepage}
}

\usepackage{blindtext}
\begin{document}
  \pagestyle{acronyms}
  \section{Acronyms}
  \begin{acronym}
    \acro{BLA}{BLA}
  \end{acronym}
  \clearpage
  \pagestyle{main}
  \blinddocument
\end{document}

Warning: Do not ignore any warning regarding the old font commands like \rm, \sl. Note that fancyhdr uses this commands in its default header and footer definitions.

Starting with the current prerelease of the next KOMA-Script Version (3.20) KOMA Script does not define this old commands, see Bekannte Probleme und Änderungen in der zukünftigen KOMA-Script-Version (German). So

\documentclass{scrartcl}[2015/11/06]
\usepackage{fancyhdr}
\pagestyle{fancy}
\begin{document}
Text
\end{document}

will result in errors. You can avoid the errors if you either use \fancyhf{} and define your own header and footer using \fancyhead and \fancyfoot without the usage of old font commands or you use a compatibility option.

Related Question