References Truncated in Beamer Presentation prepared in Knitr/RMarkdown - r

I'm currently preparing a presentation in RStudio (using RMarkdown and Knitr, outputting to a Beamer presentation) that has quite a few references.
I'm using a pretty typical YAML header:
---
title: "Title"
author: "Me"
date: "February 27th, 2016"
output:
beamer_presentation
csl: ../../apa.csl
bibliography: ../../RefenceDesk.bib
---
This presentation compiles and the references appear as they should, but unfortunately they all appear on one slide (and actually run off the page). Is there any way to have the references appear on multiple slides?

{.allowframebreaks} is the solution for multislides bibliographies in beamer. It works out of the box with regular pandoc templates (see my previous answer). However, knitr has a setting that prevents it, by redefining \widowpenalties in its beamer template. You can verify that if you examine the .tex file with keep_tex: true.
In my opinion, this is a bug. A quick fix would be to reset \widowpenalties to its default value. It can be done in your yaml front matter:
---
title: Title
header-includes:
- \widowpenalties 1 150
output:
beamer_presentation
---
Then, you can indicate the reference section as such:
## References {.allowframebreaks}

As #David above said in the comments:
For me it didnt work with ## References {.allowframebreaks} but it worked out with # References {.allowframebreaks}.
I would like to point out that, apparently for the reference slide to work you have to create a last slide with the same heading level es set by slide_level: __ at the YAML section.
So, the user should set one of the following:
# References {.allowframebreaks}. for those using slide_level: 1, OR
## References {.allowframebreaks}. for those using slide_level: 2, OR
### References {.allowframebreaks}. for those using slide_level: 3 and so on...

While this goes outside of using the regular pandoc citation template, I have found another approach that can be used to put the references across slides but it relies on the natbib citation package.
In the YAML front matter, I added:
---
title: "Title"
output:
beamer_presentation:
citation_package: natbib
bibliography: ../../RefenceDesk.bib
biblio-style: "apalike"
---
The reference slide does not get a title and I cannot seem to adjust the font size (by using a \scriptsize at the end of the .Rmd file), but at least they appear coherently.
EDIT: For parsimony, I removed the csl: ../../apa.csl line, since natbib does not require it.

Related

R Bookdown: Append chapter without re-rending whole book

I am rather experienced with R but new to markdown and especially bookdown. I wonder how to render a single chapter and merge it with the existing book without re-building the whole book. The reason why I am asking is that I am creating a book that contains parameterised chapters and each chapter runs very long (1-2 hours). All in all, it will be hundreds of chapters with the same analysis, but different input data and would time-wise add up. I am aware of the knit-and-merge approach, in fact, that's the reason why I chose bookdown, but somehow it is not working as expected.
I am honestly also a little bit confused by the different rendering possibilities. There is the built-book button, the knit button, serve_book(), render_book(), preview_chapter(), ... I figured that one should avoid using the knit button in bookdown and that serve_book() will automatically compile changes. My approach so far is entering serve_book() into console, where it renders the whole book, then I create a new chapter, hit save and it runs the chunks of only that chapter (exactly what I want!) and the single HTML file of the new chapter appears. However, it doesn't show them when I look at the book via the index.html file.
I am only interested in an HTML book and do not need any other output formats.
In order to recreate the problem, I am just using the bookdown example and adding chapters to it.
_bookdown.yaml
book_filename: "book_name"
new_session: yes #true
before_chapter_script: _common.R
delete_merged_file: true
language:
ui:
chapter_name: "Chapter "
_output.html
bookdown::bs4_book:
css: style.css
theme:
primary: "#10395B"
#repo: https://github.com/rstudio/bookdown-demo
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default
_index.yaml
---
title: |
![](./Logo_PureGene.png){width=200px}|
|-|
||
author: "Name"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
#output: bookdown::bs4_book
documentclass: book
bibliography: [book.bib, packages.bib]
# url: your book url like https://bookdown.org/yihui/bookdown
# cover-image: path to the social sharing image like images/cover.jpg
description: |
This is a minimal example of using the bookdown package to write a book.
The HTML output format for this example is bookdown::bs4_book,
set in the _output.yml file.
biblio-style: apalike
csl: chicago-fullnote-bibliography.csl
---
# About {-}
I would appreciate any help!
Thanks in advance :)

R Markdown: change the title of the "References" section?

I am writing a report with R Markdown in which I include references. The problem is that R markdown automatically includes references at the end of the report (without calling them with \printbibliography for example) and the section title is "References". I am writing in French so I would like the title to be "Références", but more generally is there any way to modify the title of that section?
Below is reproducible example:
---
title:
author:
date:
abstract:
output:
pdf_document:
template: NULL
number_sections: true
citation_package: biblatex
bibliography: references.bib
biblio-style: bwl-FU
---
# Partie 1
\cite{greenwood_financial_1989}
# Partie 2
bla bla
and here is the content of the references.bib file:
#article{greenwood_financial_1989,
title = {Financial Development, Growth and the Distribution of Income},
url = {https://www.nber.org/papers/w3189},
number = {3189},
journaltitle = {NBER Working Paper Series},
date = {1989},
author = {Greenwood, Jeremy and Jovanovic, Boyan}
}
Does anybody have a solution?
Here's the solution that combines this answer on doing something similar with bibtex and this one on the TeX required to do it in biblatex, plus #Ralf's comment about adding lang: fr
---
title:
author:
date:
abstract:
output:
pdf_document:
template: NULL
number_sections: true
citation_package: biblatex
bibliography: references.bib
biblio-style: bwl-FU
lang: fr
---
In my document, I used :
header-includes:
- \usepackage[french]{babel}
And your Contents section also changes.
I had a similar problem I wanted to place the bibliography above a supplemental section and placing <div id = "refs"></div> where you want the references successfully repositioned the section. I also had no problem renaming the section by simply changing the # title above that section. This did work for PDF output as well as HTML despite appearing to be an HTML only solution, though I was also using the markdown flavored ([#Smith2019]) references in the body of my document I don't know if using the LaTeX style will affect things.

`bookdown`/`rmarkdown`/`knitr`: YAML header elements dependent on `knitr::opts_knit$get('rmarkdown.pandoc.to')`?

Imagine a bookdown yaml header along the lines of:
---
title: Example
output:
bookdown::pdf_book:
base_format: "function(..., number_sections) rmarkdown::beamer_presentation(...)"
number_sections: yes
bookdown::pdf_document2
geometry: margin=1in, a4paper
---
Compiling this works when using the bookdown::pdf_document2 target, but fails with a \usepackage{caption} option clash for the bookdown::pdf_book target.
I would like to invoke the geometry header entry ONLY for the bookdown::pdf_document2 target, but all experimentation with
!r ifelse(knitr::opts_knit$get('rmarkdown.pandoc.to') %in% c('beamer'), '', 'margin=1in, a4paper')
(with many iterations of ''/NA/'.na'/NULL/'null' etc.) fails, as any empty setting for geometry still interferes.
I also could not find access to the yaml header content from the body of the bookdown/rmarkdown file (aiming to use knitr::opts_knit$set(<SOMETHING>) to modify the header-derived data structure from there).
Yet another option might be to move the top-level parameter geometry below the bookdown::pdf_book or bookdown::pdf_document2 levels - but there appears to be no facility for such overrides at that level.
How would I go about rendering an option like geometry conditional on the output type?

How to insert appendix after references in Rmd using Rstudio?

I am using Rstudio, to create a pdf / html document from an Rmd file. The header looks sth like this:
title: "Title"
author: "Me"
date: "`r format(Sys.time(), '%B %d, %Y')`"
bibliography: bibliography.bib
output:
html_document:
toc: true
number_sections: true
Now, I have some sections, and then include the references. After that, an appendix should follow, but I encounter the exact same problem as described here: Pandoc insert appendix after bibliography
There is a fixed solution in this thread, but I have no idea how I can do that within RStudio directly. To get the document, I just press the "Knit html" button, and do not run any pandoc commands myself. So where should I put the
--include-after-body
part, and how should the appendix rmd file look like?
As noted in the rmarkdown manual, you could use this syntax:
---
output:
html_document:
includes:
after_body: appendix.md
---
This is equivalent to the general way to add arbitrary pandoc arguments to a Rmd file:
---
output:
html_document:
pandoc_args: ["--include-after-body=appendix.md"]
---
The following might be easier; works if you knit to PDF, Word or HTML:
Everything I wanted to say in the main document.
# References
<div id="refs"></div>
\newpage
# Appendix
Some details that will bore the readers of the main document.
In the original post, this was also posted as an answer (few years after current question was asked): see https://stackoverflow.com/a/44294306/8234333 and https://stackoverflow.com/a/16428699/8234333

How to add table of contents in Rmarkdown?

I am using RStudio for writing markdown documents and want to add Table of Contents (TOC) at top of the documents so that the user could click the relevant section for reading. There were some relevant examples on rpubs but now I can't seem to find them. Please note that I don't use pandoc and am quite new to Rmd & knitr. Is there any way to add TOCs without using pandoc? If using pandoc is must then which functions are relevant?
EDIT
Here's a small sample page:
---
title: "Sample Document"
output:
html_document:
toc: true
theme: united
---
Header 1
---------------
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
## Header 2
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
### Header 3
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
I tried running this in RStudio v 0.98.864 and it worked! but sadly it didn't work on 0.98.501 and 0.98.507. I am working on my thesis in 0.98.501 and after updating RStudio, some of my analyses didn't work. So, I reverted back to 0.98.501.
What should I do now? I really want TOCs but without harming the outputs of other analyses.
The syntax is
---
title: "Sample Document"
output:
html_document:
toc: true
theme: united
---
in the documentation. Make sure this is at the beginning of your document. Also make sure your document actually has headers otherwise R can't tell what you want in the table of contents.
Syntax with more options:
---
title: "Planets"
author: "Manoj Kumar"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
html_document:
toc: true # table of content true
toc_depth: 3 # upto three depths of headings (specified by #, ## and ###)
number_sections: true ## if you want number sections at each table header
theme: united # many options for theme, this one is my favorite.
highlight: tango # specifies the syntax highlighting style
css: my.css # you can add your custom css, should be in same folder
---
If you are using pdf_document, you might want to add table of contents in a new page, which toc: true does not allow. It puts the table of contents right after the document title, author and date--because it is in yaml.
If you want to have it in a new page, you have to use some latex language. Here is what I did.
---
title: \vspace{3.5in}"Title"
author: "Name"
date: "`r Sys.Date()`"
output:
pdf_document:
fig_caption: true
number_sections: true
---
\newpage # adds new page after title
\tableofcontents # adds table of contents
\listoffigures
\listoftables
\newpage
So, after yaml (the chunk between ---), I added a new page using \newpage, then a table of contents using \tableofcontents, a list of figures using \listoffigures, a list of tables \listoftables, and a new page before everything else.
Note, \vspace{3in} in the title adds vertical space of 3 inch from the top before printing yaml (title, etc.).
Read more here: https://www.sharelatex.com/learn/Table_of_contents

Resources