Sign up ×
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.

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).

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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


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

share|improve this answer
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
@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
Okay, I'll leave it like that then. Thanks. – Mk12 Jun 27 '12 at 23:18

Your Answer


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.