Total number of pages in quarto PDF

Hello,

I need to make pdf reports in format: page number / total number of pages

Unfortunately, I can't find any information on this topic in Quarto documentation.

I suppose it is possible trough yaml header but I'm not proficient with that.

Can somebody pleas recommend some resources from where I can learn how to do this?

best regards Radek

Try adding

  - \usepackage{lastpage}
  - \usepackage{fancyhdr}
  - \pagestyle{fancy} 
  - \cfoot{\thepage\ of \pageref{LastPage}}

to the YAML.

2 Likes

Thank you.
It was bit more complicated, but you directed me to the right package.

pagestyle{fancy} works but:

  • not on the first page of report (probably because maketitle sets pagestyle to plain) - I work in regulated documentation system, and all pages of custom reports have to be numbered that way.
  • it ruins elegant Tufte-like quarto report default by adding header rule and chapter title over it.

But fancyhdr package documentation is quite clear and I managed to make this:

format:
    pdf: 
     include-in-header:
       - file: pagenumbers.tex

In the pagenumbers.tex file:

\usepackage{lastpage}
\usepackage{fancyhdr}
\fancypagestyle{fancy}{
 \fancyhf{} % clear all header and footer fields
 \fancyfoot[C]{\thepage\ of \pageref*{LastPage}} 
 \renewcommand{\headrulewidth}{0pt}
 \renewcommand{\footrulewidth}{0pt}
}
\fancypagestyle{plain}{
 \fancyhf{}
 \fancyfoot[C]{\thepage\ of \pageref*{LastPage}} 
 \renewcommand{\headrulewidth}{0pt}
 \renewcommand{\footrulewidth}{0pt}
}
\pagestyle{fancy} 

It gives me desired page numbering on all pages and make no other modification to the report headers and footers (wchich are clear in my report format).

Thank you very much for your help.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.