I'm using pagedown::chrome_print()
to render R Markdown to PDF. As of a month or so ago the internal links in the PDF have changed. I have a small table of contents on the first page of my document that links to the document sections. However, when I click on a link it takes me to the page after the start of the corresponding section.
This is how I'm generating the PDF:
pagedown::chrome_print("section-links.Rmd")
Here's a minimal R Markdown to demonstrate the problem.
---
title: "Sections with Links"
output: pagedown::html_paged
---
- [About](#about)
- [Introduction](#introduction)
- [Methods](#methods)
- [Analysis](#analysis)
- [Conclusion](#conclusion)
\newpage
## About
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
\newpage
## Introduction
Morbi elementum a erat egestas condimentum.
\newpage
## Methods
Vestibulum at fringilla nisl.
\newpage
## Analysis
Curabitur condimentum eros dui, tempor malesuada lacus interdum sed.
\newpage
## Conclusion
Aenean vestibulum diam justo, in porta nunc pretium sed.
This is what the first page looks like:
Now if I click on the Introduction link then this is where I go.
Interestingly you can see that the correct page (Page 3) is highlighted in the table of contents but the actual page displayed (Page 4) is the page after the required heading.
This happens systematically for all of the internal links.
There's a HTML file generated in the process and the links there work fine. So my suspicion is that the issue lies with the HTML to PDF conversion process.
Upon further investigation I have found that this issue exists with the most recent stable versions of Chrome and Chromium but not with earlier versions:
Is there a way around this with current versions of the browser or do I need to pin to an older version?
The issue is known to Google and has been fixed in the upcoming version 127.0.6533.43.
I do not think it can be circumvented in the affected versions.