【问题标题】:How to show the total number of pages in a PDF via the RMarkdown (i.e. display "Page 1 of 10")?如何通过 RMarkdown 显示 PDF 中的总页数(即显示“第 1 页,共 10 页”)?
【发布时间】:2022-01-17 10:01:53
【问题描述】:

鉴于下面的代码,它当前在页面顶部输出页码,我希望它输出 PDF 页数,如Page 1 of 3。我做了很多搜索,但没有找到包含总页码的任何方法。

问题这可以用 R Markdown 做吗?如果没有,有什么解决方法吗?

我用谷歌搜索了这个,没有发现任何明显的东西,例如 YAML 或 TeX 解决方案,但是,我可能遗漏了一些东西或没有搜索正确的东西。

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

当前标题

所需的标题

【问题讨论】:

    标签: r r-markdown knitr pandoc tex


    【解决方案1】:

    确保您已安装 lastpage 软件包。

    然后修改您的标题包含如下所示:

    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}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-08
      • 2012-04-17
      • 1970-01-01
      • 2021-03-13
      相关资源
      最近更新 更多