Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to fix the head for a long html flextable?

I am trying to have sticky headers like tables produced with kableExtra which is useful when inspecting long tables and was wondering if anyone has an idea how this may be doable with flextable.

Here's an example Rmd to get an idea of what I mean. I'd like the flextable header to be fixed at the top of the page when scrolling down just like in the kable.

---
output: bookdown::html_document2
---

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

library(flextable)
```

## My Kable

```{r mykable}
iris |>
  kableExtra::kbl(caption = "a caption") |>
  kableExtra::kable_styling(fixed_thead = TRUE)
```

## My Flextable

```{r myflextable}
flextable(iris) |>
  set_caption("a caption")
```
like image 894
Patrick Avatar asked Jan 24 '26 12:01

Patrick


1 Answers

Similar to your other question, we can add some custom CSS:

flextable::set_table_properties(opts_html = list(
    extra_css = "
      thead th {
        position: sticky !important;
        top: 0 !important;
        background-color: white !important;
        z-index: 1000 !important;
      }
    "
  ))
like image 167
M-- Avatar answered Jan 27 '26 02:01

M--