1

I am trying to change the pagination on the first page of my references section. I've been using fancyhdr to customize the pagination in my headers per the requirements of the thesis format at my school. In the article class, the first page of a chapter gets its first page style reset to plain, so the fancyhdr style never applies since it goes overwritten. The fancyhdr manual offers a solution by saying to edit the plain style, but I need to keep the plain style because I am using that elsewhere. So my question is, how can I set the header/footer on the first page of my references section so that it uses the fancy style, without editing the plain pagestyle?

Here is a MWE:

\documentclass[12pt]{report}
\usepackage[natbibapa]{apacite}
\usepackage{lipsum}

\usepackage{fancyhdr}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[R]{\thepage}
\pagestyle{fancy}

\begin{document}

\chapter{Test}
\thispagestyle{fancy} %% This works
\lipsum[1-4]
\citep{R, lme4, MCMCglmm, MASS, lmerTest, gplots, foreign, CAR, brms}

\bibliographystyle{apacite}
\thispagestyle{fancy} %% This doesn't work
\bibliography{References}
\thispagestyle{fancy} %% Nor this

\end{document}

With a References.bib file containing:

@Manual{R,
    title = {R: A Language and Environment for Statistical Computing},
    author = {{R Core Team}},
    organization = {R Foundation for Statistical Computing},
    address = {Vienna, Austria},
    year = {2015},
    url = {https://www.R-project.org/},
}

@Article{lme4,
    title = {Fitting Linear Mixed-Effects Models Using {lme4}},
    author = {Douglas Bates and Martin M{\"a}chler and Ben Bolker and Steve Walker},
    journal = {Journal of Statistical Software},
    year = {2015},
    volume = {67},
    number = {1},
    pages = {1--48},
    doi = {10.18637/jss.v067.i01},
}

@Article{MCMCglmm,
    title = {MCMC Methods for Multi-Response Generalized Linear Mixed Models: The {MCMCglmm} {R} Package},
    author = {Jarrod D Hadfield},
    journal = {Journal of Statistical Software},
    year = {2010},
    volume = {33},
    number = {2},
    pages = {1--22},
    url = {http://www.jstatsoft.org/v33/i02/},
}

@Manual{lmerTest,
    title = {lmerTest: Tests in Linear Mixed Effects Models},
    author = {Alexandra Kuznetsova and Per {Bruun Brockhoff} and Rune {Haubo Bojesen Christensen}},
    year = {2015},
    note = {R package version 2.0-29},
    url = {https://CRAN.R-project.org/package=lmerTest},
}

@Book{MASS,
    title = {Modern Applied Statistics with S},
    author = {W. N. Venables and B. D. Ripley},
    publisher = {Springer},
    edition = {Fourth},
    address = {New York},
    year = {2002},
    note = {ISBN 0-387-95457-0},
    url = {http://www.stats.ox.ac.uk/pub/MASS4},
}

@Manual{gplots,
    title = {gplots: Various R Programming Tools for Plotting Data},
    author = {Gregory R. Warnes and Ben Bolker and Lodewijk Bonebakker and Robert Gentleman and Wolfgang Huber Andy Liaw and Thomas Lumley and Martin Maechler and Arni Magnusson and Steffen Moeller and Marc Schwartz and Bill Venables},
    year = {2015},
    note = {R package version 2.17.0},
    url = {https://CRAN.R-project.org/package=gplots},
}

@Manual{foreign,
    title = {foreign: Read Data Stored by Minitab, S, SAS, SPSS, Stata, Systat, Weka,
dBase, ...},
    author = {{R Core Team}},
    year = {2015},
    note = {R package version 0.8-66},
    url = {https://CRAN.R-project.org/package=foreign},
}

@Book{CAR,
    title = {An {R} Companion to Applied Regression},
    edition = {Second},
    author = {John Fox and Sanford Weisberg},
    year = {2011},
    publisher = {Sage},
    address = {Thousand Oaks {CA}},
    url = {http://socserv.socsci.mcmaster.ca/jfox/Books/Companion},
}

@Manual{brms,
    title = {brms: Bayesian Regression Models using Stan},
    author = {Paul-Christian Buerkner},
    year = {2015},
    note = {R package version 0.6.0},
    url = {https://CRAN.R-project.org/package=brms},
}

I had to make the References section longer than a page in this MWE because otherwise, the single page is paginated correctly. But when longer than 2 pages, I can't seem to get the references section to use the fancy pagestyle on the first page.

2
  • Have you tried \afterpage{\thispagestyle{fancy}} before starting the references? (Need afterpage package.) Mar 7, 2016 at 2:24
  • Just gave it a shot, no luck. I think the afterpage commands probably get executed first, and then once latex processes that its a new chapter, it resets the the page style to plain. Mar 7, 2016 at 3:15

2 Answers 2

2

If you don't want to redefine plain (even temporarily), you can redefine thebibliography (from apacite.sty).

\documentclass[12pt]{report}
\usepackage[natbibapa]{apacite}
\usepackage{lipsum}

\usepackage{fancyhdr}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[R]{\thepage}
\pagestyle{fancy}

\makeatletter
\def\thebibliography#1{%
  \@ifundefined{chapter}%
    {\st@rtbibsection}%
    {\if@sectionbibdefault
       {\@ifundefined{@mainmatterfalse}%
          {\st@rtbibchapter\thispagestyle{fancy}}%
          {\if@mainmatter
             \st@rtbibsection
           \else
             \st@rtbibchapter\thispagestyle{fancy}%
           \fi
          }%
       }%
     \else
        \if@sectionbib
          \st@rtbibsection
        \else
          \st@rtbibchapter\thispagestyle{fancy}%
        \fi
     \fi
    }%
  \bibliographytypesize % e.g., to put the bibliography in \small type
  \bibliographyprenote  % some explanatory note before the references
  \@ifundefined{APAC@metaprenote@\APAC@extra@b@citeb}%
    {}% skip
    {\csname APAC@metaprenote@\APAC@extra@b@citeb\endcsname}%
  \list{\relax}{\labelsep=\biblabelsep
                \parsep=\bibparsep
                \itemsep=\bibitemsep
                \leftmargin=\bibleftmargin
                \itemindent=\bibindent}% changed to cope with 4th ed.
   \def\newblock{\hskip .11em plus .33em minus .07em}%
   \sloppy\clubpenalty4000\widowpenalty4000
   \sfcode`\.=1000\relax %'
   \bt@beg@thb@hook
   \APACrestorebibitem
}
\makeatother

\begin{document}

\chapter{Test}
\thispagestyle{fancy} %% This works
\lipsum[1-4]
\citep{R, lme4, MCMCglmm, MASS, lmerTest, gplots, foreign, CAR, brms}

\bibliographystyle{apacite}
\bibliography{references}

\end{document}

Alternatively, you could just add

\makeatletter
\let\ps@plain=\ps@fancy
\makeatother

just before the bibliography.

3
  • Unfortunately, it seems that redefining thebibliography environment overrides a lot of other customizations I've made (which I left out to keep the MWE as minimal as possible) as well as some of the APA formatting from natbib. Notice that in your example, the hanging indents get removed. However, setting plain to fancy just before the bib does the trick, so thank you! But I am wondering, is there a way to adjust thebibliography environment so it doesn't mess with formatting? It also removed references from my toc and wont let me change the bibname (both done with tocbibind). Mar 7, 2016 at 18:29
  • 1
    I replaced the version from report.cls with the one from apacite.sty. Mar 8, 2016 at 0:15
  • The second solution worked like a charm for me without messing up any other settings that I had.
    – pegah
    Jul 31, 2022 at 14:25
1

Here is a solution. We need to redefine plain style

\documentclass[12pt]{report}
\usepackage[natbibapa]{apacite}
\usepackage{lipsum}

\usepackage{fancyhdr}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[R]{\thepage}
\pagestyle{fancy}

\begin{document}

\chapter{Test}
\thispagestyle{fancy} %% This works
\lipsum[1-4]
\citep{R, lme4, MCMCglmm, MASS, lmerTest, gplots, foreign, CAR, brms}

\bibliographystyle{apacite}

\fancypagestyle{plain}{%
\fancyhf{}
\fancyhead[R]{\thepage}}
\bibliography{References}

\end{document}
2
  • Sorry but I explicitly stated in the question that changing the plain style is not an option for me, I need that style for other sections in the document. Mar 7, 2016 at 9:53
  • 1
    my bad, sorry you can try \begingroup\fancypagestyle{plain}{% \fancyhf{} \fancyhead[R]{\thepage}} \bibliography{References}\endgroup?
    – touhami
    Mar 7, 2016 at 17:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .