Make Scrollbar appear in RMarkdown code chunks (html view)

前端 未结 1 1333
遥遥无期
遥遥无期 2020-12-31 21:02

I am making an RMarkdown document using RStudio and knitr. I want my code chunks to print without wrapping text on the html file I create. Is there an option I am missing

相关标签:
1条回答
  • 2020-12-31 21:41

    try:

    ---
    title: "Stop looking bad RMarkdown!"
    output: html_document
    ---
    
    <style>
    pre code, pre, code {
      white-space: pre !important;
      overflow-x: scroll !important;
      word-break: keep-all !important;
      word-wrap: initial !important;
    }
    </style>
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    options(width=200)
    ```
    
    #### I want this to print without text wrapping:
    
    ```{r }
    x <- matrix(nrow = 3, ncol = 20, data = 1)
    x
    ```
    

    NOTE that with more recent versions of R markdown you can replace the <style> tags with:

    ```{css}
    pre code, pre, code {
      white-space: pre !important;
      overflow-x: scroll !important;
      word-break: keep-all !important;
      word-wrap: initial !important;
    }
    ```
    
    0 讨论(0)
提交回复
热议问题