2

My RMarkdown file is not wrapping either code, text, or code block output when I knit to PDF with several LaTeX engines.

Here is an example of the my code I'm having trouble with.

---
title: "Test_for_text_runoff"
author: "username"
date: "2/19/2021"
output:
  pdf_document: default
---

```{r}
print("ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh")
```

mooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

This code produces the following PDF output, of which I have taken a screenshot. screenshot of PDF

I have already found a number of other posts that talk about similar issues:

  1. This person has the same problem that I do: https://community.rstudio.com/t/r-knit-to-pdf-how-to-wrap-long-lines/14829. There are two solutions offered on this page. The first solution (https://github.com/rstudio/rmarkdown/issues/646) suggests editing the code chunk header to wrap the code chunk, however my problem extends to text outside the chunk and also the output of a chunk. Also, I have tried loading the formatR library and using Tidy = TRUE inside the code chunk header.
  2. Some solutions on this page suggested using width.cutoff arguments in the chunk header, but that has also not worked in my code chunks (In R markdown in RStudio, how can I prevent the source code from running off a pdf page?). In particular, my problem does not only involve code chunks, but also text outside of the chunk.

Perhaps there is no solution for this, as other posters have suggested. However, it seems to me that there should be some way to specify the width of a PDF to LaTeX using the YAML header. Any suggestions? Thanks!

Update: As a temporary work around, I am knitting to a Word doc (has correct code/text margins) then saving as a PDF.

0 Answers0