简体   繁体   中英

How to remove border box around R Markdown HTML output using Knitr chunk options

When knitting R code chunks to HTML in R Markdown, it's possible to alter certain visual elements by setting chunk options (figure height, displaying messages/warnings, etc.). I'm curious about whether there's a chunk option to remove the gray border around the box that the code returns into. For example, if I run the following:

```{r}
head(mtcars)
```

It outputs like this: 代码输出

The code appears on a light gray background with a gray border, and the return appears on a white background with a gray border. Is there a way to remove the gray border around the code, the return, or both?

Thank you for the help.

You can add

<style>
    pre {
        border: 0;
    }
</style>

somewhere in your .Rmd outside of a code chunk. This will give you this .

To elaborate on why this works, both the code block and return are wrapped in a <pre> tag when knitted, which is for pre-formatted text. You can verify this by simply viewing the page source for a knitted Rmarkdown page. So, using CSS, you can specify no border for these tags.

The same can be done to avoid borders around images:

<!-- avoid border around images -->
<style>
    img {
        border: 0;
    }
</style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM