How do I insert a logo before the document title? - r

I would like the logo that I'm inserting in my document to appear before the document title. How do I achieve this?
Here is my preamble:
---
title: My Document Title
author:
date:
output: pdf_document
toc: false
geometry: left=0.3in, top=0.3in, right=0.3in, bottom=0.5in
fontsize: 12pt
classoption: portrait, onecolumn
---
and the knitr chuck I am inserting the logo with:
```{r, out.width = "400px", fig.align = "center", echo=FALSE}
knitr::include_graphics("path/imagename.png")
```
As it is, the title appears first, then the logo.

Related

Links between child documents in RMarkdown

I am writing my PhD thesis in R Markdown and I would like to add links to one child document (Introduction) allowing the reader to jump to another child document (one of the papers).
This is my main document:
---
output:
pdf_document:
latex_engine: pdflatex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F)
```
```{r chapter1, child = 'child1.Rmd'}
```
\newpage
```{r chapter2, child = 'child2.Rmd'}
```
This is how I tried to link my child1 and child2:
This is my second child document. Here I want a link to [`Child document 1`](./child2.Rmd#header1).
But when I click on the "Child document 1", it jumps to the original rmd file.
TLDR: is it possible to add clickable links between different child documents??
R version 4.2.2, Ubuntu 20, rmarkdown 2.18
Hi it works the same way as internal links.
Parent document:
---
output:
pdf_document:
latex_engine: pdflatex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F)
```
# Parent Header
implicit internal Link to header [Parent Header]
## Child links:
This implicit links to child 1 [C1 Second header]
Here I give a explicit link to [Go to second child](#child2_header1)
\newpage
# Child 1
```{r chapter1, child = 'child1.Rmd'}
```
\newpage
# Child 2
```{r chapter2, child = 'child2.Rmd'}
```
Child 1:
---
title: "child1"
author: "Valentin Haberl"
date: "`r Sys.Date()`"
output: pdf_document
---
## I am a child document {#child1_header1}
## C1 Second header
Some more Info
Child 2.
---
title: "child2"
author: "Valentin Haberl"
date: "`r Sys.Date()`"
output: pdf_document
---
## I am a second child {#child2_header1}
Text for second child

How to edit footer in RMarkdown using the fancyhdr package

I have created a PDF in RMarkdown with the fancyhdr package in LaTeX. I'm trying to find a solution in which I can insert a horizontal line as a footer (just above the page number), as well as the page number in the right hand corner similar to the image I have attached. Additionally, is there a way in which I can change the color of all the hyperlinks (such as the table of contents) from the default black color to the same color as in the image?
My YAML is as follows
---
title: "Template for a Dynamic Report for Work"
Uni_Logo: Tex/logo.jpg
Author1: "Tangeni Shatiwa"
# ----- Manage headers and footers:
#BottomLFooter: $Title$
#BottomCFooter:
#TopLHeader: \leftmark # Adds section name at topleft. Remove comment to add it.
BottomRFooter: "\\footnotesize Page \\thepage" # Add a '#' before this line to remove footer.
addtoprule: TRUE
addfootrule: TRUE # Use if footers added. Add '#' to remove line.
toc: TRUE
numbersections: TRUE # Should sections (and thus figures and tables) be numbered?
fontsize: 11pt # Set fontsize
linestretch: 1.2 # Set distance between lines.
link-citations: TRUE # This creates dynamic links to the papers in reference list.
linkcolor: blue
output:
pdf_document:
includes:
in_header: "header.tex"
---
and the contents of the header.tex file are as follows
\usepackage{fancyhdr}
\usepackage{titling}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\setlength{\headheight}{50pt}
\lhead{\includegraphics[width = .2\textwidth]{logo.jpg}}
\fancyfoot[R]{\thepage}
\renewcommand{\footrulewidth}{0pt}
\pretitle{%
\begin{center}
\LARGE
\includegraphics[width=4cm,height=6cm]{logo.jpg}\\[\bigskipamount]
}
\posttitle{\end{center}}
TIA!
Here's an example rmarkdown document and header.tex file. I removed the logo lines in header.tex since I don't have your logo. Let me know if this is what you had in mind.
rmarkdown file
---
title: "Template for a Dynamic Report for Work"
Author1: "Tangeni Shatiwa"
BottomRFooter: "\\footnotesize Page \\thepage" # Add a '#' before this line to remove footer.
addtoprule: TRUE
addfootrule: TRUE # Use if footers added. Add '#' to remove line.
toc: TRUE
numbersections: TRUE # Should sections (and thus figures and tables) be numbered?
fontsize: 11pt # Set fontsize
linestretch: 1.2 # Set distance between lines.
link-citations: TRUE # This creates dynamic links to the papers in reference list.
urlcolor: darkred
output:
pdf_document:
includes:
in_header: "header.tex"
---
\newpage
\pagenumbering{arabic}
Some text
[This is a link to Stack Overflow](www.stackoverflow.com)
Some more text
\newpage
Even more text
---
\newpage
\pagenumbering{arabic}
Some text
[This is a link to Stack Overflow](www.stackoverflow.com)
Some more text
\newpage
Even more text
header.tex file
\usepackage{fancyhdr}
\usepackage{titling}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot[L]{This is the left footer}
\fancyfoot[R]{\thepage}
\fancyfoot[C]{}
\setlength{\headheight}{50pt}
%\lhead{\includegraphics[width = .2\textwidth]{logo.jpg}}
\renewcommand{\footrulewidth}{1pt}
\pretitle{%
\begin{center}
\LARGE
%\includegraphics[width=4cm,height=6cm]{logo.jpg}\\[\bigskipamount]
}
\posttitle{\end{center}}
\pagenumbering{gobble}
\usepackage{xcolor}
\definecolor{darkred}{rgb}{0.7,0,0}
PDF output

How can I separate the title page from the table of contents in a RMarkdown Word output?

How can I separate the title page from the table of contents in a RMarkdown Word output? I've seen a lot on here about pdf and html output, but not much about Word. I've tried to use a little bit of LaTex, but it seems that most of that only works with pdf output, and the bit that does work with Word doesn't do what I'm looking for.
---
title: "Sample Title"
subtitle: "Sample Subtitle"
date: "April 8, 2020"
output:
word_document:
toc: yes
---
\newpage
# Header 1
sample text
## Header 2
more sample text
# Another Header 1
loren ipsum
## Another Header 2
foo bar
This just puts a blank page after the table of contents, not before. It feels like there is something simple that I'm missing.
You may consider exploring the officedown package and its block_toc function (together with <!---CHUNK_PAGEBREAK---> inline yaml):
---
title: "Sample Title"
subtitle: "Sample Subtitle"
date: "April 8, 2020"
output:
officedown::rdocx_document
---
<!---CHUNK_PAGEBREAK--->
# Table of Contents
`r officedown::block_toc(level = 5, style = NULL, separator = ";")`
<!---CHUNK_PAGEBREAK--->
# Header 1
sample text
## Header 2
more sample text
# Another Header 1
loren ipsum
## Another Header 2
foo bar
Or even simple, as discussed here:
<!---CHUNK_PAGEBREAK--->
# Table of Contents
<!---BLOCK_TOC--->
<!---CHUNK_PAGEBREAK--->
To place the toc wherever needed without messing with tex files (here with a pdf output),
Turn off automatic toc insertion first in the YAML metadata.
---
title: "myTitle"
date: "`r Sys.Date()`"
output:
pdf_document:
toc: no
number_sections: true
urlcolor: blue
editor_options:
chunk_output_type: console
documentclass: report
---
Then, wherever you want the toc to be in your document, add
```
{=latex}
\setcounter{tocdepth}{4}
\tableofcontents
```
You can then place this toc anywhere using latex macros such as \newpage or \hfill\break for example.
---
title: "myTitle"
date: "`r Sys.Date()`"
output:
pdf_document:
toc: no
number_sections: true
urlcolor: blue
editor_options:
chunk_output_type: console
---
\newpage
```{=latex}
\setcounter{tocdepth}{4}
\tableofcontents
```
\newpage
Note: documentclass: report in the metadata will automatically separate the toc from the title, but won't allow to separate it from the remainder of the document.
Source

xaringan slide separator not separating slides

In this example xaringan presentation, why are both the ## blank page and the leaflet map on the same slide, given I've separated them by the new-slide separator --- ?
---
title: "map test"
output:
xaringan::moon_reader:
css: ["default"]
nature:
highlightLines: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## blank page
content
---
leaflet page
```{r}
library(leaflet)
leaflet() %>%
addTiles()
```
---
Looks like you've got an unintended space after the new slide separator after blank content as "--- ". Remove that space and it'll be recognized as real slide separator:
---
title: "map test"
output:
xaringan::moon_reader:
css: ["default"]
nature:
highlightLines: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## blank page
content
---
leaflet page
```{r}
library(leaflet)
leaflet() %>%
addTiles()
```
---
In my case I'm adding mathjax/latex equations and I had:
$$
\begin{aligned} P(Y= k)=\comb{k-1}{r-1} * p^r q^{k-r}, \qquad k= r,r+1
\end{aligned}\label{pascal}\tag{5}
$$
And I had to remove the breaklines
$$\begin{aligned} P(Y= k)=\comb{k-1}{r-1} * p^r q^{k-r}, \qquad k= r,r+1
\end{aligned}\label{pascal}\tag{5}$$
and then it worked. I've that it renders mathjax better if all the code is in a single line.

can I produce a figure caption in r markdown with eval=false?

If I have the MWE:
---
title: "Example"
output:
pdf_document:
fig_caption: yes
---
Text text text
```{r fig.cap="Figure 1. Some random numbers",eval=FALSE}
summary(cars)
```
then I do not get a caption. But if I do:
---
title: "Example"
output:
pdf_document:
fig_caption: yes
---
Text text text
```{r fig.cap="Figure 1. Some random numbers"}
summary(cars)
```
i.e. remove eval=FALSE then the caption no longer loads.
why I wish to do this?
I want to put example bits of code into my document. the code won't actually work, hence why I want to supress it. Something like
---
title: "Example"
output:
pdf_document:
fig_caption: yes
---
Text text text
```{r fig.cap="Figure 1. Some random numbers",eval=FALSE}
for (i in 1:length(c){
#do something
}
```
where I am merely demonstrating a for loop, but not actually running the code.
As far as I know, knitr doesn't support captions for code by default. The easiest way to label your code blocks would be to add an explanation below the box in the markdown.
If you must have captions in the r code, you can use chunk hooks. Here's an example for your case:
---
title: "Example"
output:
pdf_document:
fig_caption: yes
---
```{r}
library(knitr)
knit_hooks$set(wrapper = function(before, options, envir) {
if (!before) {
sprintf(options$comment)
}
})
```
```{r comment="Figure 1. Some random numbers",wrapper=TRUE,eval=FALSE}
for (i in 1:length(c){
#do something
}
```
We have defined a hook (wrapper), where if we call wrapper=TRUE in any chunk options, the comment argument is printed below.

Resources