4

I've added the last page package tried to display the pager but the last page wont display. What's wrong with my code, the last page will just display a "??":

{.select date_format(now()," %M %d, %Y %r") as  run_date}
{.select username from deskpad.user where user_id=@user_teller}

\documentclass{article}
\usepackage[paperheight=11in,paperwidth=8.5in,margin=0.1in,headheight=0.5in,footskip=0.4in,includehead,includefoot]{geometry}
\usepackage{graphicx}
\usepackage{fancyheadings}
\usepackage{fancybox}
\usepackage{longtable}
\usepackage{setspace}
\usepackage{textcomp}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{fancyhdr}
\usepackage{lastpage}

\usepackage[absolute]{textpos}

\renewcommand{\familydefault}{\sfdefault}

\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}

\fancyhf{}
\fancyhead[l]{
}
\fancyfoot[l]{
\small{
\begin{tabular}{p{4.0in} p{4.0in}}
\hspace{15pt} \small{ \emph{ Date Printed: {.\run_date\} } } & \raggedleft{ \small{ \emph{ Page \thepage\ of \pageref{Last Page} } } \hspace{15pt}} \tabularnewline
\end{tabular}
}
}
  • 1
    Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Aug 22 '13 at 15:28
9

The correct key is \pageref{LastPage}, without spaces. Two LaTeX runs are necessary for getting the correct reference when the number of pages changes: on the first run the value is written in the .aux file and read back in in the following run.


Here's also a better way to achieve the same result for the footer, using the L and R fields without any guess about the widths.

Note that fancyheadings is obsolete and should not be loaded, fancyhdr is sufficient.

I omitted also the packages not necessary for the example; the kantlipsum package is just to provide the \kant command that produces mock text.

\documentclass{article}
\usepackage[
  paperheight=11in,
  paperwidth=8.5in,
  margin=0.1in,
  headheight=0.5in,
  footskip=0.4in,
  includehead,
  includefoot
]{geometry}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{lastpage}

\usepackage{kantlipsum}

\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}

\fancyhf{}
\fancyfoot[L]{%
  \small\hspace{15pt}\emph{Date Printed: \today}%
}
\fancyfoot[R]{%
  \small\emph{Page \thepage\ of \pageref{LastPage}}\hspace{15pt}%
}

\begin{document}

\kant[1-20]

\end{document}
| improve this answer | |
6

You need \pageref{LastPage}, since the label is LastPage, not Last Page. You may also have to compile your document at least twice (as a start), in order for the reference to show up correctly. See Understanding how references and labels work.

| improve this answer | |
  • 1
    still not displaying....I just learned that it's normal. Needs to be compiled twice to complete the document. – eggshot Aug 22 '13 at 14:25

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.