Encountering difficulties in achieving a visually pleasing document using knitr's export to pdf, I have resorted to converting the html file for my Markdown project to pdf through the wkhtmltopdf command line utility tool.
A simplified Markdown document exemplifies my dilemma:
---
title: "Untitled"
output:
html_document:
df_print: paged
toc: true
number_sections: true
---
## ALPHA Header
### Alpha sub-1
### Alpha sub-2
## BETA Header
### Beta sub-1
### Beta sub-2
Upon conversion, this results in an html file with a table of contents but without page breaks when utilizing wkhtmltopdf for conversion.
Referencing responses from this Github query, I attempted to implement the custom CSS style type suggestion. It should be noted that I am not well-versed in html/CSS.
I adjusted the markdown code following the YAML (remaining unchanged) as follows:
<style type="text/css" media="screen,print">
/* Page Breaks */
/***Always insert a page break before the element***/
.pb_before {
page-break-before: always !important;
}
</style>
<div class="page1 pb_before">
## ALPHA Header
</div>
<div class="page2 pb_before">
### Alpha sub-1
</div>
<div class="page3 pb_before">
### Alpha sub-2
</div>
<div class="page4 pb_before">
## BETA Header
</div>
<div class="page5 pb_before">
### Beta sub-1
</div>
<div class="page6 pb_before">
### Beta sub-2
</div>
Although after knitting this version, the numbering system for headers and the table of contents vanish, now each header has its own separate page upon conversion to pdf using wkhtmltopdf.
Hence, my question revolves around how to merge these two elements together - ensuring a table of contents with numbered headers post-html export, along with prepped html/CSS code enabling page breaks following each header when converted via wkhtmltopdf.