rr-markdownquarto

How can I center the output of general R results in Quarto?


In a Quarto document that creates HTML output, I can print general R object and the results will be left aligned in Quarto. How can I center or right align general R objects? In addition, is there a way I could add a gray background to this output?

The code provided is from a default template Quarto file, and the image shows the results being left aligned by default.

```{r}
mtcars
```

Left aligned R output


Solution

  • Extending from this answer,

    ---
    title: "Test"
    format: html
    css: style.css
    ---
    
    ```{r}
    #| classes: styled-output
    mtcars
    ```
    
    

    style.css

    .styled-output .cell-output {
      background-color: #c8cac8;
    }
    
    .styled-output .cell-output pre {
      max-width: fit-content;
      margin-left: auto;
      margin-right: auto;
    }
    

    Output Screenshot