Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RMarkdown: how to rotate table column headers

Tags:

css

r-markdown

I'm trying to rotate table column headers in RMarkdown. Since I don't have an understanding of CSS my attempts so far have proven to be futile.

So, how can I rotate the table column headers?

Here is a minimal example for a table in RMarkdown:

---
title: "Untitled"
output: 
  html_document:
    df_print: paged
    style: ./Table.css
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(kableExtra)
library(knitr)
```

<div class="table-header-rotated">

```{r test, result="asis"}

kable(head(mtcars), "html")
```
</div>

And the CSS file was made from the code presented here: https://codepen.io/chriscoyier/pen/Fapif

Can anyone give me a hint?

like image 981
mcenno Avatar asked Mar 05 '18 11:03

mcenno


1 Answers

You could just use kable_styling() and row_spec() from kableExtra.

---
title: "Untitled"
output: 
  html_document:
    df_print: paged
    style: ./Table.css
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(kableExtra)
library(knitr)
```

<div class="table-header-rotated">

```{r test, result="asis"}
kable(head(mtcars), "html") %>%
kable_styling("striped", full_width = F) %>%
  row_spec(0, angle = -45)
```

yields: enter image description here

like image 64
jay.sf Avatar answered Oct 15 '22 22:10

jay.sf