How can I make a conditional in my custom documentclass (based on article) for when the document is only one page long?

I need this because when it is only one page, I don't want to put the page number in the footer (but if there is multiple pages, I do want the page number on the first page—so it's not simply a matter of giving the first page a numberless footer).


Here is one option, using a combination of refcount and lastpage:

\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{lastpage}% http://ctan.org/pkg/lastpage
\usepackage{refcount}% http://ctan.org/pkg/refcount

The idea is to check the value of the last page's number in an expandable form using \getpagerefnumber of the LastPage label (offered by lastpage). I doubt whether pageslts is required here.

I've used \pagestyle{empty}, but you could change this to whatever page style you want to. For example, if you're using fancyhdr and you want to define a footer-less page style that still contains a header.

lipsum is just for dummy text, Lorem Ipsum style. Here's a two-page output (the above MWE):

enter image description here

Here's a one-page output:

enter image description here

  • Thanks! How would I change the conditional to not, so that it only sets \fancyfoot[R]{\small \thepage\ of \pageref{LastPage}} when its not 1? I tried != and that isn't it. – mk12 Jun 27 '12 at 23:06
  • 1
    @Mk12: I would set the default have the footer \fancyfoot[R]{\small \thepage\ of \pageref{LastPage}} and then keep my original conditional to remove it for the first page. \ifnum\getpagerefnumber{LastPage}=1\fancyfoot{}\fi. In general, for != conditioning, you could use \ifnum<num1>=<num2>\else<!= clause>\fi. Also see the etoolbox package documentation for more on conditional statements. – Werner Jun 27 '12 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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