Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

image path

like image 726
Emre Toros Avatar asked Nov 01 '25 23:11

Emre Toros


1 Answers

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.

like image 198
Rshad Zhran Avatar answered Nov 03 '25 12:11

Rshad Zhran