RMarkdown pdf document chunk output exceeds page margins - latex

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.

Related

Can we use the bib file from web for pdf_book in Bookdown?

In Rmarkdown,
we can generate pdf file if we use the bib file from a url.
For example, we set
bibliography: [https://raw.githubusercontent.com/ChoCho66/test/main/text.bib]
In bookdown, we can also generate html book (gitbook, bs4_book)
if we use the bib file from a url.
But pdf_book doesn't work.
It has the following message.
! Undefined control sequence.
\hyper#normalise ...M{ }\catcode `\%\active \let %
\#percentchar \let \%\#per...
l.430 ...content.com/ChoCho66/test/main/text.bib}}
The tex file has wrong since the following:
\bibliography{\url{https://raw.githubusercontent.com/ChoCho66/test/main/text.bib}}
Is there any way to solve this problem?
I want a common code that can compile both html book and pdf book if we use bib url file.

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

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!

Size of the embeded PDF document in Rmarkdown

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

Resources