Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
682 views
in Technique[技术] by (71.8m points)

r - Adjusting width of tables made with kable() in RMarkdown documents

Is it possible to adjust the width of columns when making tables with the kable() function in knitr?

A chunk like this for a table with two columns produces a table that takes up the entire width of the document. I'd like to make the columns narrower. Can this be done with kable() or is another package needed?

This rmarkdown chunk

```{r}
df <- data.frame(x = 1:10,
           y = 11:20)
library(knitr)
kable(df)
```

Produces this table enter image description here

Aligning left with kable(df, align = "l") helps a little but I'd like the two columns adjacent to each other.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can try out the kableExtra package.

kable(x, "html") %>%
  kable_styling(full_width = F)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...