Inserting custom-spaced page breaks in Rmarkdown HTML output - r-markdown

I have a rmarkdown script that generates html of some maps and tables. Sometimes, one of the tables is shorter than usual and the next header shifts upward into the space of the previous section. Here is an example of what is happening:
Missing Page-Break Example
I am trying to get the header of the next section to be below both the "LOB" and "Location" tables. Is there a simple way (using css, html, rmarkdown, etc) to get around this without having to create a custom page breaker that measures the number of rows of the previous table?

In Rmarkdown, i usually use <br> </br> syntax for small breaks in HTML code, according to the R Markdown Cookbook for breaks you use \newpage, but that only worked for me for PDF output
---
title: Breaking pages
output: pdf_document
---
# The first section
\newpage
# The second section

Related

Dynamic footnote referencing in rmarkdown / bookdown

I am combining several .Rmd-files into one large document using bookdown. The individual files all contain footnotes, starting with ^[1]. This obviously leads to duplicate footnotes in the final document, with bookdown unable to assert which reference belongs to which footnote.
As a consequence, I am wondering whether there is a way to dynamically generate footnotes when the document is rendered, but I could not find anything related to that in the bookdown docs.
I have this working solution using a custom function:
---
title: "Untitled"
output:
html_document:
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
footnote.nr <- 0
footnote.counter <- function(){
footnote.nr <- footnote.nr + 1
.GlobalEnv$footnote.nr <- footnote.nr
return(footnote.nr)
}
```
Lorem ipsum.[^`r footnote.counter()`]
[^`r footnote.nr`]: Test
Lorem ipsum.[^`r footnote.counter()`]
[^`r footnote.nr`]: Test2
However, this would result in me having to retrofit the entire document which would be just as much manual labor as starting footnote numbering completely anew (though it is probably less error prone). Are there any other solutions? I would also be okay with footnotes being rendered for each individual chapter, meaning that the first footnote in each chapter starts with a 1.
In my humble opinion, #jtbayly's answer is only partially correct as using Rstudio's visual editing mode can indeed prompt it to make automatic changes to your text by adding a unique identifier before the citation (ex: [^love1]).
However, that did not initially work for me, and I had to add, for each child document the following option in the yaml header :
editor_options:
markdown:
references:
prefix: "[insert the unique identifier you want for this child document]"
This should then work, and would allow you to compile multiple .Rmd files into a single large document without RMarkdown/Pandoc messing with the citations. However, don't forget to go back to "Source" mode and "Visual" mode once after editing the yaml header for the editor to make the change.
Another option is to use Rstudio to edit your files, and turn on visual editing. If you do, it will make some automatic changes to your text, including giving your footnotes unique names.

TOC problem when knitting Rmarkdown document with images

Finished and published on github my first website using Distill package in RStudio:
https://crlnp.github.io/3-objets.html
On this particular page I include several images in my rmarkdown document and it causes problems with the table of contents: the headings are duplicated and don't follow the headings adequatly. I have tried every toc_float: option available and it does not solve the problem. Aldo tried changing the heading levels (all #, ...). The problem appears wether the image is inserted traditionally or in a code bloc. If I take out the images in my file, the TOC works perfectly. I have not been able to find any information on this issue. Thanks in advance for any help!
Your .Rmd file on the website (GitHub) repo.
If you include JS file (optional) and move wrapping div container, from current position to above your first header, TOC behaviour will change:
<script src="hideOutput.js"></script>
<div class="fold o">
## 1. Les objets
.
.
.
</div>
Is this helpful in any way?
Output:

Changing citation style to number-letter in papaja Rmarkdown package

I'm writing a scientific manuscript in RMarkdown using the papaja package, which enables me to report my statistics beautifully. However, the journal now requires me to submit a Word document with number-letter referencing. Is it possible to change the referencing style to a number-letter style in Papaja?
I tried opening the LaTeX output from papaja, but it has the citations set out in the text in APA format (e.g. "Apthorp, Bolbecker, Bartolomeo, O'Donnell, \& Hetrick, 2018"), which is not useful to me.
Here's the code from the top of the manuscript:
bibliography : ["PD_sway-1.bib"]
floatsintext : no
figurelist : no
tablelist : no
footnotelist : no
linenumbers : yes
mask : no
draft : no
documentclass : "apa6"
classoption : "man"
output : papaja::apa6_pdf
It would be great if I could get a Word document with number-letter referencing that I could then edit, but a LaTeX file or PDF with the correct citation format would be fine too.
The references are already typed out in APA style in the LaTeX document because they are handled by pandoc-citeproc rather than LaTeX. This has the advantage that the automatic reference formatting also works when you output your document in Word format. To get a Word document all you need to do is change the output line in the YAML front matter:
output: papaja::apa6_docx
Note that the formatting of Word documents that pandoc supports is somewhat limited and you may have to fix some things manually. From the corresponding section in the papaja manual:
More over, rendered documents in DOCX format require some manual work before they fully comply with APA guidelines.
We, therefore, provide the following checklist of necessary changes:
Always,
add a header line with running head and page number
If necessary,
position author note at the bottom of page 1
move figures and tables to the end of the manuscript
add colon to level 3-headings
in figure captions,
add a colon following the figure numbers and italicize(e.g. "Figure 1. This is a caption.")
in tables,
add horizontal rules above the first and below the last row
add midrules
Changing the citation style works just as it does in any R Markdown document. The work-in-progress papaja manual has a section on this:
Other styles can be set in the YAML front matter by specifying a CSL, or Citations Style Language, file. You can use either one of the large number of existing CSL files, customize an existing CSL file, or create a new one entirely.
To change the citation style, download the CSL file and add the following to the YAML front matter:
csl: "path/to/mystyle.csl"
I'm not sure what style the journal requires but most likely a corresponding CSL file already exists.

Chapter(s) before table of contents in Bookdown PDF output

I'd like for a chapter to appear before the table of contents (but after the title page) in the pdf_book output of Bookdown.
One way to do this is to add the chapter to a .tex file and and link it using before_body:. However, this means the chapter will not appear in gitbook (which I also need). I'd prefer not to keep both a .tex and .Rmd version of the same chapter.
An ideal solution would be if the chapter could be kept in a .Rmd file, and its contents extracted into the before_body for pdf_book. That way it's still available for gitbook. Though I'm not sure how I might do that, or indeed if it's possible?
Is there a solution? Or is it exceeding the limits of Bookdown's flexibility?
Any help would be greatly appreciated, thanks!
One can trigger ToC creation manually in the document, which gives more control over its placement. Of course, automatic table of contents creation should be disabled:
---
title: "MWE"
output:
bookdown::pdf_book:
toc: False
---
```{r child = 'file-you-want-to-include.Rmd'}
```
```{=latex}
% Trigger ToC creation in LaTeX
\tableofcontents
```
# Rest of your document starts here
The downside is that this only works with PDF output, not HTML.

Linking to url with rmarkdown using Knit Word in Rstudio

Is there an easy way to link to a webpage in rmarkdown without displaying the link?
For example, putting "https://www.google.com/" in a .rmd file renders as the entire website, but I want something analogous to ABC instead.
The html method above, i.e., <a href= ... works when I knit to html, but it does not work when I knit to a word document.
Markdown provides two ways to create a link as you mention (and I suppose that is supported on rmarkdown).
Markdown way:
[ABC](http://example.com)
HTML way:
ABC
The first way is native and the second way is supported since Markdown allows every HTML code.