TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 6 down vote accepted

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

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.