How to have Frontpage Image before chapter title and book title? - r

Is that possible to have FrontPage Image
a) BEFORE first chapter title,
b) BEFORE book title?
Currently the only way to include any frontpage image seems to be AFTER the first-level (non-empty) heading, like below:
---
knit: "bookdown::render_book"
site: bookdown::bookdown_site
documentclass: book
author: "Me Mine"
title: "«My Book»"
---
# Frontpage
```{r, echo=FALSE, out.width="60%", fig.align = "center"}
knitr::include_graphics( "nice-frontpage-image.jpg" )
)
# Introduction
...
It would have been so much better if I can do this (without having to have unneeded #Frontpage chapter):
---
knit: "bookdown::render_book"
site: bookdown::bookdown_site
documentclass: book
author: "Me Mine"
title: "«My Book»"
---
```{r, echo=FALSE, out.width="60%", fig.align = "center"}
knitr::include_graphics( "nice-frontpage-image.jpg" )
)
# Introduction
...
And this (i.e. image goes before the title):
---
knit: "bookdown::render_book"
site: bookdown::bookdown_site
documentclass: book
author: "Me Mine"
title: `r knitr::include_graphics( "nice-frontpage-image.jpg" )`
)"\n «My Book»"
---
# Introduction
...
Is that possible?
PS
I found a related still unaswered question here:
Index.Rmd without first-level heading

Related

Create a hyperlink from the logo to the table of contents slide in an rmarkdown::beamer_presentation with a custom beamer theme

I use a custom LaTex beamer theme in an rmarkdown::beamer_presentation.
As per these SO answers (LaTex theme, colon, theme path), I used several modifications of the YAML header and beamerthemeTHEMENAME.sty.
These LaTex hacks are necessary to apply the LaTex Beamer theme smoothly in the rmarkdown::beamer_presentation.
For the foot line defined in beamerouterthemeTHEMENAME.sty, it would be very nice to have a hyperlink from the logo to the table of contents slide (like the slide numbers are linked to the appendix).
What I tried: define custom foot line in beamerouterthemeTHEMENAME.sty
\mode<presentation>
...
% Foot line
\setbeamertemplate{footline}{
\leavevmode%
\hyperlink{toc---table-of-contents}{\includegraphics[width=12mm,trim=0mm 0.4mm 0mm 0mm]{img/my_logo.png}}
\hfill
\hyperlinkappendixstart{\insertframenumber/\inserttotalframenumber}
\vspace{3mm}
}
\mode<all>
For a complete MWE, see my SO question here.
In normal beamer code, you could simply attach a label to the frame, but Rmarkdown seems to be too stupid to correctly parse the square brackets in \begin{frame}[label=outline].... annoying!
As a workaround you could use something like a section name for which markdown will automatically insert a label:
---
subtitle: "Beamer presnetation with R-markdown"
institute: "some place"
date: "`r format(Sys.time(), '%B %d, %Y')`"
author: "Donald Duck"
output:
# beamer_presentation: default
bookdown::pdf_book:
base_format: rmarkdown::beamer_presentation
# includes:
# in_header: preamble.tex
theme: "THEMENAME"
latex_engine: xelatex
toc: false
slide_level: 2
keep_tex: true
header-includes:
- \AtBeginDocument{\title{MWE}\titleframe}
- \AtEndDocument{\begin{closingframe}lalala\end{closingframe}}
- \makeatletter\beamer#ignorenonframefalse\makeatother
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Outline {.unnumbered}
\tableofcontents
# section
## Slide with Bullets
<!-- ======================================================== -->
- Bullet 1
- Bullet 2
- Bullet 3
<!-- Appendix -->
<!-- ======================================================== -->
``` {=latex}
\end{frame}
\appendix
\begin{frame}
```
and use this target in the footline
% Footline
\setbeamertemplate{footline}{
\leavevmode%
\hyperlink{outline}{\includegraphics[width=12mm,trim=0mm 0.4mm 0mm 0mm]{example-image}}
\hfill
\hyperlinkappendixstart{\insertframenumber/\inserttotalframenumber}
\vspace{3mm}
}

xaringan set the document title dynamically

In r-markdown is is an option to move the title: out of the main yaml, as described in the R Markdown Cookbook.
But, in a xaringan slide set the new --- seems to conflict with the idea of new slide.
The below code works, but when move line #2, title: "Presentation Ninja" outside the main yaml, and inset it as title: "The name of the dog is r dog_name!", by removing all my <!-- ... --> code in line #17-19, it does not work as expected. I do no longer get a title page. I guess I need to work around the --- in xaringan?
Any help would be appreciated!
---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
output:
xaringan::moon_reader:
lib_dir: libs
---
# xaringan set the document title dynamically
```{r, code=xfun::read_utf8('script_with_many_dog_names.R')}
```
The name of the dog is `r dog_name`!
<!-- --- -->
<!-- title: "The name of the dog is `r dog_name`!" -->
<!-- --- -->
Some bullets
- Foo
- Bar
You could use R Markdown parameters :
Create a template file Template.Rmd
---
title: "The name of the dog is `r params$dog_name`"
subtitle: "⚔<br/>with xaringan"
author: "John Doe"
output:
xaringan::moon_reader:
lib_dir: libs
params:
dog_name: NA
---
# xaringan set the document title dynamically
Some bullets
- Foo
- Bar
Render the template after setting dog_name parameter :
source('script_with_many_dog_names.R')
# As an example, but it could be the result of previous script
params <- list(dog_name = 'Charles')
rmarkdown::render('Template.Rmd', output_file = 'presentation.html',
params = params,
envir = new.env(parent = globalenv())
)
You can add your logic directly to the title, that seems to work fine for me:
---
title: "The number is `r round(100 * runif(1), 2)`"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
output:
xaringan::moon_reader:
lib_dir: libs
---

Omit index page from the Bookdown TOC

I am using bookdown to write a book with a web-version, using the bs4_book format. I want my index page (the front page) to not appear in the TOC on the left, i.e. I want the blue circled item in this screenshot not to appear in the TOC:
I tried the directions in the documentation:
# Section name {.unlisted .unnumbered}
but it is to no avail. My pandoc version is > 2.7 as indicated:
> rmarkdown::pandoc_version()
[1] ‘2.11.0.4’
These are the contents of _bookdown.yaml
book_filename: "shiny-book"
language:
ui:
chapter_name: "Chapter "
delete_merged_file: true
new_session: no
rmd_files:
[
"index.Rmd",
"test_chapter.md",
]
_output.yml
bookdown::bs4_book:
repo: https://github.com/smsaladi/phd
includes:
in_header: [ga_script.html, no_robots.html]
index.Rmd
---
title: "Investigations on the computer"
author: "Name"
site: bookdown::bookdown_site
---
`r if (knitr::is_latex_output()) '<!--'`
# Preface {.unlisted .unnumbered}
`r if (knitr::is_latex_output()) '-->'`

Do not indent the first paragraph of a new section

I would like to indent every paragraph but the first paragraph of every section in my article. The Rmd file has a pdf_output and it is referencing child files containing the sections of my article.
This is what I have:
---
bibliography: bibliography.bib
header-includes:
- \usepackage{setspace}\doublespacing
- \usepackage{float}
- \setlength{\parskip}{12pt}
#- \setlength{\parindent}{30pt}
fontsize: 12pt
indent: true
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
```{r 01_Introduction, child = here::here("WriteUp", "Child", "Introduction.Rmd")}
```
\newpage
# References
I would like to indent every paragraph but the first paragraph of every section in my article.
You use indent in the YAML. See this answer.
Here is an example. First the main file:
---
title: "test"
author: "me"
date: "11/3/2020"
output: pdf_document
indent: true
---
```{r, child=c('sec1.Rmd', 'sec2.Rmd')}
```
Here is the sec1.Rmd file:
## My section
Some text.
Some more text.
and here is the sec2.Rmd file:
# That other section
Even more text.
And the last line.
The result is:
Update
It is still indented after I have added:
header-includes:
- \usepackage{setspace}\doublespacing
- \usepackage{float}
- \setlength{\parskip}{12pt}
to the YAML.

R notebook font size

What are my options for changing the font size of dynamically-generated output, when rendering to a PDF? My document currently looks something like this:
---
title: "Foo"
author: "Bar"
date: "`r format(Sys.time(), '%B %e, %Y')`"
output:
pdf_document: default
html_document:
df_print: paged
header-includes: \usepackage{amsmath} \usepackage{color}
---
# Introduction
```{bash echo=FALSE}
perl -le 'print for 1..50'
```
I want to decrease the font size to help more output fit on a single page of the PDF. I'm not currently also outputting to HTML, so a cross-format solution would be cool but not really necessary.
It is as simple as fontsize: 12pt (or of course fontsize: 9pt as we use in pinp)
Modified file:
---
title: "Foo"
author: "Bar"
date: "`r format(Sys.time(), '%B %e, %Y')`"
fontsize: 12pt
output:
pdf_document: default
html_document:
df_print: paged
header-includes: \usepackage{amsmath} \usepackage{color}
---
# Introduction
```{bash echo=FALSE}
perl -le 'print for 1..50'
```
If you want it just for code / result snippets I would suggested you place appropriate \begin{Large} and \end{Large} around it. I have in the past customized the default environments used here --- as I recall knitr more or less follows Sweave here. Just look at the generated .tex file.

Resources