rmarkdown text out of margin in pdf documnet

Hello, I have the problem with the output text in the pdf document going out of margin when the document is rendered using rmarkdown::render with output_format = 'pdf_document'. This can be avoided by using knit button in RStudio but sometimes I need the documents being generated by running scripts. Here is a reproducible example:

---
title: "Test"
output: pdf_document
geometry: margin=2cm
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, tidy.opts = list(width.cutoff = 40), tidy = TRUE)
```

```{r}
print(rep("ABCDEFGH", 20))
```

I'm using
rmarkdown_2.28
pdfTeX 3.14159265-2.6-1.40.21 (TeX Live 2020)
kpathsea version 6.3.2
R version 4.4.0

Thank you for any suggestions.

When running knit button, it will also use rmarkdown::render() so I don't see why there would be a difference :thinking: I am really surprised by this, so I looked into it

So it is possible that the background process started by RStudio IDE does set some options.

Cell output width is controlled by the option width and I see that by default on my R console it is

> getOption("width")
[1] 176

and this will be used with rmarkdown::render(). So you need to change this.

See about width of text output

So I would advice to change this option in your document setup chunk like you do with tidy.opts

Thanks @cderv , this solution works!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.