[英]How to show the total number of pages in a PDF via the RMarkdown (i.e. display "Page 1 of 10")?
Given the code below, which currently outputs the page number on top of the page, I would like it to output the PDF page count as in Page 1 of 3
.鉴于下面的代码,它当前在页面顶部输出页码,我希望它到 output PDF 页数,如
Page 1 of 3
。 I have done a lot of searching but haven't found any way to include the total page number.我做了很多搜索,但没有找到任何方法来包含总页码。
Question Is this possible to do w/ in R Markdown?问题这可以在 R Markdown 中执行吗? If not, are there any workarounds?
如果没有,是否有任何解决方法?
I have googled this and haven't found anything obvious such as YAML or TeX solutions, however, I may be missing something or not searching for the correct things.我用谷歌搜索了这个,没有发现任何明显的东西,比如 YAML 或 TeX 解决方案,但是,我可能遗漏了一些东西或没有寻找正确的东西。
RMarkdown Code RMarkdown 代码
---
title: "R Markdown Example With Numbered Sections"
output:
bookdown::pdf_document2:
toc: true
toc_depth: 6
number_sections: true
includes:
in_header: header.tex
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[RO,RE]{\thepage}
- \fancyhead[LO,LE]{Header Message}
- \fancyfoot[LE,LO]{Footer Messge on the Left}
- \fancyfoot[LE,RO]{Footer Messge on the Right}
---
\thispagestyle{fancy}
# Example R Rarkdown : Numbered Sections
## R Markdown
### Description
Some description text
\newpage
#### Details
Details go here.
\newpage
## Plots
Plots go here
\newpage
Last page
Current header当前 header
Desired Header所需的 Header
Make sure you have the lastpage
package installed.确保您已安装最后
lastpage
。
Then modify your header includes to look like this:然后修改您的 header 包括如下所示:
header-includes:
- \usepackage{fancyhdr}
- \usepackage{lastpage}
- \pagestyle{fancy}
- \fancyhead[RO,RE]{\thepage\ of \pageref{LastPage}}
- \fancyhead[LO,LE]{Header Message}
- \fancyfoot[LE,LO]{Footer Messge on the Left}
- \fancyfoot[LE,RO]{Footer Messge on the Right}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.