1

I am trying to display some regression results in an rmarkdown html file. However, the output from the code chunks is too narrow and therefore it is very hard to read the p-values, etc, particularly when I include a floating table of contents. I have tried adjusting options(width = 9999) but this does not seem to fix the issue. I have also tried:

<style>
pre {
  overflow-x: auto;
}
pre code {
  word-wrap: normal;
  white-space: pre;
}
</style>

which allows me to scroll horizontally if needed. However, given I am using regression results, I do not like having to scroll back and forth to read the coefficients and p-values. I have also tried:

<style>
.main-container { width: 1200px; max-width:2800px;}
</style>

adjusting the width and max-width values, to no avail. These solutions are suggested here.

Any idea how I can solve this issue?

Here is an example. Unfortunately I cannot post my regression results, so here is a matrix that essentially replicates the same issue:


---
title: "Untitled"
author: "me"
date: "11/10/2021"
output: 
    html_document:
      toc: true
      tow_float: true
     
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
options(width = 9999)
matrix = matrix(rnorm(100,5,2), ncol = 20)
matrix

However, when I knit the document, I get something like this:

enter image description here

How can I make the output wider?

z_11122
  • 153
  • 8
  • Does this answer your question? [Width of R code chunk output in RMarkdown files knitr-ed to html](https://stackoverflow.com/questions/36845178/width-of-r-code-chunk-output-in-rmarkdown-files-knitr-ed-to-html) – manro Nov 10 '21 at 19:20
  • @manro This is the post I referenced in my post. I tried the things suggested here, and they seem to work when I do not have a table of contents. However, when I include the TOC they don't seem to work – z_11122 Nov 12 '21 at 16:57
  • hmm... I will see – manro Nov 12 '21 at 18:57

1 Answers1

1

I found out, where is your problem.

The floating toc is guilty.

Look, I took a code from that post and remove toc_float.

---
title: "R Notebook"
author: "me"
date: "11/10/2021"
output:
  html_document:
    toc: true    
---


<style>
.main-container { width: 1800px; max-width:2800px;}
</style>

## R Markdown

```{r}
options(width = 1500)
dataM <- matrix(rnorm(100, 5, 2), ncol = 20)
dataM
```

And it works:

enter image description here

I think, that this space under toc is reserved. But can't say it with 100% confidence.


An addition

You should make a custom TOC with CSS. I'm not a pro with CSS, so, I have compiled something for you. You can modify it...

CSS-file:

#TOC { 
    font-family: Arial, Helvetica, sans-serif; 
    color:black; 
    background-color: white;     
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 150px; 
    border: 1px solid Black;
    padding: 10px; 
    margin: 30px;
    overflow:auto;      
 }

body {
  max-width: 800px;  
  margin-left:210px;
  line-height: 20px;
}

Your header:

---
title: "R Notebook"
author: "me"
date: "11/10/2021"
output:
  html_document:
    css: TOC.css
    toc: true
---

enter image description here

manro
  • 3,529
  • 2
  • 9
  • 22