Home > front end >  How to make a table with inner lines in r markdown when kniting to PDF?
How to make a table with inner lines in r markdown when kniting to PDF?

Time:11-13

I made a table in rmd with the following code:

|Option|Description|
|----|----|
|Text1|Description1|
|Text2|Description2|
|Text3|Description3|

When kniting to PDF, the table was rendered as a three-line table.

enter image description here

I don't like three-line tables very much, because when the tables are long and wide, sometimes it's hard to quickly figure out which row the cells on the right of the table correspond to.

So, I wonder if there is a way for the tables in the pdf generated from rmd to be rendered as non-three-line tables, just like typora do. enter image description here

I googled the problem but couldn't find a solution.

CodePudding user response:

1st option

Try flextable library. For instance:

```{r} 
library(dplyr)
library(flextable)
data.frame(Option = c("Option1", "Option2", "Option3"), Description = c("Text1", "Text2", "Text3")) %>% 
  flextable() %>% 
  theme_box() # or  theme_vanilla()
```

And lateron adjust the required themes and/or formating.

2nd option

Try kable as well:

library(kableExtra)
library(dplyr)
library(knitr)
data.frame(Option = c("Option1", "Option2", "Option3"), Description = c("Text1", "Text2", "Text3")) %>% 
  
kable() %>%
  kable_styling(full_width = TRUE) %>%
  row_spec(2, background = "lightgray")
  • Related