I'm using the CRC template to make a book and trying to force breaking of lines in some R output. I made a trivial example and can't get it to work. I'm trying to incorporate recommendations here to break the lines of R output in a PDF but I can't get it to work.
See example of what I changed here
Overview:
Added listings package to preamble.tex \usepackage{listings}
Set option to break lines in before_body.tex \lstset{breaklines=true}
Added a chunk of wide output using
options(width=200)
1:100
When I made the PDF, it doesn't break the lines as expected.
Any ideas?
Note: this is cross-posted
1 Like
Had trouble repping this as bookdown, so played with the simpler Rmd case, which seems it should carry over. See header-include
in the YAML
and results='asis'
in final chunk. Remove leading '
to cut-and-paste.
---
title: "width"
author: "Richard Careaga"
date: "2023-07-03"
output: pdf_document
header-includes:
- \usepackage{listings}
- \lstset{breaklines=true, postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space}}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(tidy = TRUE, width = 40)
`## R Markdown
This is an R Markdown document set to render in pdf, as a simpler alternative to narrow the issues on the Bookdown case.
'### Global knitr option to reduce chunk margins in set up (to 40) had no effect
'### The default case
Chunk output wrapped
'{r} 1:100 '
'### Using chunk option to allow wider than margin output
'{r} options(width=200) 1:100 '
'### Omitted option next chunk does not restore previous default
'{r} 1:100 '
'### Width option has to be expressly reset
'{r} options(width=60) 1:100 '
' ### Wrapping wide output with tex markup
'{r, results='asis'} options(width=200) 1:100 '
cderv
July 5, 2023, 3:48pm
3
@technocrat See FAQ: How to Format R Markdown Source
This is necessary to format correctly the source code and it is easy enough. Thank you !
system
Closed
August 19, 2023, 3:49pm
4
This topic was automatically closed 45 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.