Skip to content

Conversation

@wangben718
Copy link
Collaborator

@wangben718 wangben718 commented Dec 18, 2025

Add Page Number Hardcoding Feature for Multi-Page Tables

Summary

This PR implements a new \pagenumber_hardcoding control word that enables per-page page numbering in multi-page RTF tables. Unlike the existing \pagenumber (which uses RTF field codes), this feature hardcodes the actual page numbers during table generation, ensuring accurate page numbering for table-specific pages (e.g., "Page 1 of 3", "Page 2 of 3", etc.).

Problem Statement

Previously, when creating multi-page tables, users could use \pagenumber which relies on RTF's dynamic field codes. However, this approach has limitations:

  • It shows the document page number, not the table-specific page number
  • For tables spanning multiple pages, users needed table-relative page numbering (1/3, 2/3, 3/3)

Solution

Added a new control word \pagenumber_hardcoding that:

  1. Gets converted to an internal placeholder \pgnhardcoding during text conversion
  2. Is replaced with the actual page number (1, 2, 3, etc.) on a per-page basis during table encoding
  3. Works together with \totalpage which is also replaced with the total number of pages
image image

@wangben718 wangben718 linked an issue Dec 18, 2025 that may be closed by this pull request
@wangben718 wangben718 requested a review from elong0527 December 18, 2025 17:00
@wangben718 wangben718 changed the title add //pagenumver_hardcoding add //pagenumber_hardcoding Dec 18, 2025
Copy link
Collaborator

@elong0527 elong0527 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add PR description with screenshot to show it works as expected?

Also update vignettes to clarify the new control words

@wangben718 wangben718 merged commit d19a6fe into master Dec 28, 2025
8 checks passed
@pgseye
Copy link

pgseye commented Jan 4, 2026

Thank you very much for adding this option. Once I can get it working it will be invaluable for me. I am having some issues at the moment, however. When I run the following code (verbatim as your example) I get the attached. I have tried escaping the underscore but that doesn't fully solve the issue either. I have version 1.2.0 installed - do I need a different version?

tbl3_file <- tempfile(fileext = ".rtf")
tbl4_file <- tempfile(fileext = ".rtf")
# Create a multi-page table to demonstrate page numbering within a single table
iris[1:100, ] |>
  rtf_title("Table 1: Iris Data (\\pagenumber_hardcoding/\\totalpage)") |>
  rtf_colheader("Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species") |>
  rtf_body(col_rel_width = rep(1, 5)) |>
  rtf_encode() |>
  write_rtf(tbl3_file)
# Single page table to show independent numbering
iris[101:130, ] |>
  rtf_title("Table 2: Iris Data (\\pagenumber_hardcoding/\\totalpage)") |>
  rtf_colheader("Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species") |>
  rtf_body(col_rel_width = rep(1, 5)) |>
  rtf_encode() |>
  write_rtf(tbl4_file)
assemble_rtf(
  input = c(tbl3_file, tbl4_file),
  output = "rtf/page-number-hardcoding.rtf"
)

page-number-hardcoding.rtf

@elong0527
Copy link
Collaborator

You can install it from github using remotes::install_github("Merck/r2rtf") or wait a newer version on CRAN.

@pgseye
Copy link

pgseye commented Jan 4, 2026

You can install it from github using remotes::install_github("Merck/r2rtf") or wait a newer version on CRAN.

It works perfectly - thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible to add auto-table numbering across multi-page tables?

4 participants