简体   繁体   English

如何通过 RMarkdown 显示 PDF 中的总页数(即显示“第 1 页,共 10 页”)?

[英]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.

相关问题 如何在 Rmarkdown 中选择页码? - How can i choose the page number in Rmarkdown? 如何在 rmarkdown 中设计 PDF 页面? - How to design PDF page in rmarkdown? 如何让 tab_model 在 Rmarkdown PDF 中正确显示? - How to I get tab_model to display properly in Rmarkdown PDF? 如何使用magick::image_read_pdf获取pdf文件的总页数? - How to get total number of pages of pdf files using magick::image_read_pdf? 如何在 r ggplot package 中将可缩放时间数据作为一个因素呈现? (即 1 小时、5 小时、10 小时) - How to present scalable time data as a factor in the r ggplot package? (i.e. 1 hour, 5 hour, 10 hour) dplyr和lubridate-按小时和分钟(即10:15)过滤 - dplyr & lubridate - filter by hour and minute (i.e. 10:15) 如何在R中计算属于同一数据帧中处理组合的列中的记录数(即行,单元格)? - How to count, in R, the number of records (i.e., rows, cells) in a column belonging to a combination of treatments in the same dataframe? 如何在 R 中对具有固定事件数(即 1)的二进制 output 进行采样? - How to sample a binary output with a fixed number of events (i.e. 1) in R? 如何在 R 中为千和百万(即 1'000,000)格式化一个大数 - How to format a big number with different bigmarks for thousand and millions (i.e. 1'000,000) in R 如何删除文档Rmarkdown中标题中的数字页? - How to delete the number page in the title in a document Rmarkdown?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM