Size of the embeded PDF document in Rmarkdown - latex

I'm trying to embed a pdf document in a Rmarkdown document generated by KnitR using \includepdf. It works but included documents are very small:
The reproducible example below:
---
output: pdf_document
header-includes:
- \usepackage{pdfpages}
---
```{r, echo=FALSE}
url = 'https://www.rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf'
download.file(url, 'gg.pdf')
```
\includepdf[pages=-]{gg.pdf}
Is there a way to resize the inserted document to its original size?
I've found a possible solution but I don't know how to implement it in KnitR:
https://tex.stackexchange.com/questions/264383/pdfpages-does-not-correctly-scale-inserted-pdf-pages

Related

include Rmarkdown pdf output code into a seperate latex theisis tex file

I am trying to write a report.tex theists using TexMAKER,and I need to include a lot of r,
So I run my chunk code file with this preamble in Rmarkdow
title: "rcode"
author: ".."
date: "..."
output:
pdf_document:
keep_tex: yes
fig_caption: yes
html_document: default
then include the rcode.pdf output file in my original report.tex file using the command \includepdf[]{rcode.pdf}
this method is not so good because the page numbering in my report.pdf gets mixed up with the numbering of the Rmardown pdf output rcode.pdf,
So I am wondering if there is a new way to extract the rcode.tex code then include it in my report.tex file ?
Or is the better way just to start wring all of the theisis report in the rmardown file with out having any Latex complications ?
thanks for the help

Repeat Title and Date R Markdown PDF

I am struggling what what is likely a trivial markdown matter. I am hoping to avoid YAML and additional header templates and such if I can. So my question is straightforward and I welcome your feedback. For an R Markdown knitted as a PDF, how can I repeat the title and date on each printed page?
Alternatively I am happy to use headers using the '#' syntax. But if I can use the title parameters that would be preferred.
The Header thus far:
---
title: "Dashboard"
date: '`r paste(Sys.Date(), " to ", Sys.Date()+14)`'
output:
pdf_document:
latex_engine: xelatex
mainfont: Calibri
geometry: margin=1cm
classoption: landscape
params:
set_title: !r test_title
header-includes:
- \usepackage{titling}
- \pretitle{\begin{flushleft}\huge}
- \posttitle{\end{flushleft}}
- \preauthor{\begin{flushleft}}
- \postauthor{\end{flushleft}}
- \predate{\begin{flushleft}\large}
- \postdate{\end{flushleft}}
---
From the rmarkdown cookbook:
When a Rmd document is compiled, all of its metadata in the YAML section
will be stored in the list object rmarkdown::metadata. You can use this object
in your R code. For example, rmarkdown::metadata$title gives you the title
of the document.

Calligra font with RMarkdown

This is my Rmarkdown code:
---
title: "My Title"
header-includes:
- \usepackage{calligra}
- \usepackage[T1]{fontenc}
output:
pdf_document:
latex_engine: xelatex
---
# Section 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>.
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:
I was studying the best way to change fonts in Rmarkdown. In texlive the installed calligra package appears and calligra-type1 also.
When I run the script with the calligra package it generates the pdf but the font does not match the calligra font.
And when I run the script for calligra-type1 the pdf is not even generated.
Any help, guys?
The calligra.sty does not set-up the Calligra as default font, but you can do so by adding
\renewcommand{\rmdefault}{calligra}
to header-includes.
BTW, there is no need to call fontenc.sty, since calligra.sty does so already. In addition, using xelatex is not necessary here.

Apply knitr option function in "before_body" when using Rmarkdown to compile PDF

As question, I am using knitr option (i.e. include=temp.switch) to compile multiple reports based on the value given to a "switch" (i.e. temp.switch), this are working well for the content, but I would like to use similar function to modify the cover page of the report, which is stored in the tex file read in yaml, like the one below:
---
output:
pdf_document:
# template: template.tex
number_sections: true
keep_tex: true
includes:
in_header: preamble.tex
before_body: doc-prefix.tex
papersize: a4
editor_options:
chunk_output_type: console
---
Can anyone tell me how to make the doc-prefix.tex "conditional" based on the value of the "switch"? Thanks!

RMarkdown pdf document chunk output exceeds page margins

While I am knitting a document as a PDF using RMarkdown some code chunk outputs exceeds the page margins as seen on the pic.
Any ideas to fix this?
I think your problem could be the typo, not widt
options(width = 60) ## I usually use 50 -60
Many functions do not respond correctly to the page size config. So to solve such an issue, you have to include the following configuration for the output file.
output:
pdf_document:
pandoc_args: --listings
includes:
in_header: preamble.tex
create the file preamble.tex in the same folder where the Rmarkdown file exists, and its content is the following:
\lstset{
breaklines=true
}
For more information, check https://bookdown.org/yihui/rmarkdown-cookbook/text-width.html.

Resources