Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In the preamble of an exam I am creating, I currently have:

%headers, footers
\usepackage{fancyhdr} 
\pagestyle{fancyplain} %header
\fancyhf{} % sets both header and footer to nothing
\renewcommand{\headrulewidth}{0pt} % your new footer definitions here
\rfoot{\large \bf{GO ON TO NEXT PAGE}}

Of course, I'd like for "GO ON TO THE NEXT PAGE" to be removed on the last page. Is there any way I can do this?

Edit/Update: By the way, at the end, I ended up approaching this problem differently than what the answers below provided because the document went through many changes in the last day or so (from me asking questions on this website). I ended up defining a page style:

\fancypagestyle{laststyle}
{
   \fancyhf{}
   \fancyfoot[R]{\textbf{STOP}}
}

and putting \thispagestyle{laststyle} where I wanted it.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Add

\AtEndDocument{\thispagestyle{empty}}

to the document preamble. Alternatively, replace empty with whichever page style you want to match your other document components. What should also work is to use

\AtEndDocument{\rfoot{}}

to clear the right footer.

Here is a minimal example showing the usage and output:

enter image description here

\documentclass{article}

\usepackage{lipsum}

%headers, footers
\usepackage{fancyhdr} 
\pagestyle{fancyplain} %header
\fancyhf{} % sets both header and footer to nothing
\renewcommand{\headrulewidth}{0pt} % your new footer definitions here
\rfoot{\large \textbf{GO ON TO NEXT PAGE}}
\lfoot{\large\thepage}
\AtEndDocument{\rfoot{}}
\begin{document}

\lipsum[1-50]

\end{document}

The above may not work in all instances, as it depends on when the pages are shipped out. One may use some help from pageslts's VeryLastPage label and refcount to extract the value:

\usepackage{pageslts,refcount}

%headers, footers
\usepackage{fancyhdr} 
\pagestyle{fancyplain} %header
\fancyhf{} % sets both header and footer to nothing
\renewcommand{\headrulewidth}{0pt} % your new footer definitions here
\rfoot{\ifnum\getpagerefnumber{VeryLastPage}=\value{page}\else\large \textbf{GO ON TO NEXT PAGE}\fi}
\lfoot{\large\thepage}
\pagenumbering{arabic}
share|improve this answer
    
You're being lucky; try with \lipsum[1-48]a\\a\\a\\a –  egreg Jul 14 at 22:04
    
@egreg: Corrected using pageslts's VeryLastPage label. Probably similar to your zref-totpages approach. –  Werner Jul 14 at 22:39

The safest method is checking if the page is really the last one, which can be obtained with zref-totpages:

\documentclass{article}
\usepackage{zref-totpages}
\usepackage{lipsum}

%headers, footers
\usepackage{fancyhdr}
\pagestyle{fancy} %header
\fancyhf{} % sets both header and footer to nothing
\renewcommand{\headrulewidth}{0pt} % your new footer definitions here
\fancyfoot[R]{\ifnum\value{page}=\ztotpages\else\large \textbf{GO ON TO NEXT PAGE}\fi}
\fancyfoot[L]{\large\thepage}
\begin{document}

\lipsum[1-48]
a\\
a\\
a\\
a
\end{document}

The example, taken from Werner's answer, fails with his code: both page 9 and 10, with the simple \AtEndDocument{\rfoot{}} would have an empty footer.

Instead of \lfoot and \rfoot I prefer \fancyfoot and \fancyhead; they're almost equivalent, but the “newer” ones are better.

share|improve this answer
    
Is not \AtEndDocument{\rfoot{}} equivalent to \rfoot{}\end{document}? If yes, why does it fail? –  Sigur Jul 14 at 22:27
1  
@Sigur The page breaking mechanism is asynchronous; in the (admittedly a bit contrived) example, the last four line paragraph is typeset and the page break has not yet been decided when \end{document} is scanned. Now \end{document} executes \rfoot{} and so this setting applies also to the last but one page, because TeX decides to break the page after having performed that action. –  egreg Jul 14 at 22:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.