# PDF Latex lastpage does not work

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}

\documentclass{article}
\usepackage{graphicx}
\usepackage{fancybox}
\usepackage{longtable}
\usepackage{setspace}
\usepackage{textcomp}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{fancyhdr}
\usepackage{lastpage}

\usepackage[absolute]{textpos}

\renewcommand{\familydefault}{\sfdefault}

\pagestyle{fancy}

\fancyhf{}
}
\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}
}
}

• 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

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,
footskip=0.4in,
includefoot
]{geometry}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{lastpage}

\usepackage{kantlipsum}

\pagestyle{fancy}

\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}


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.

• 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