2

I'm using Quarto to create a website which contains a lot of tables. Because I want the tables to have a specific look, I use huxtable to add borders. Take the following as an example:

```{r}
t1 = matrix(c("",         "menu",   "",      "",     "", 
              "",         "",       "yes",   "no",   "", 
              "group",    1,        1,        4,      5,
              "",         2,        5,        1,      6,
              "",         "",       6,        5,      11),
            nrow = 5, byrow = T)

huxtable::as_hux(t1) |> 
  set_bottom_border(row = c(2,4), col = 2:5) |>
  set_bottom_border(row = c(1,5), col = c(3,4)) |>
  set_right_border(row = 2:5, col = c(2,4)) |> 
  set_right_border(row = c(3,4), col = c(1,5)) |> 
  
  merge_cells(row = 1, col = 2:5) |> 
  merge_cells(row = c(3,4), col = 1) |> 
  set_align(row = everywhere, col = everywhere, "center")
```

This used to create beautiful tables. But since I upgraded to Quarto version 1.3, when rendering it seems to override my layout-inputs with a bootstrap-design. Now it looks ridiculous: See here

Is there any way that I can suppress the bootstrap-layouting?

I tried setting the background to white using set_background_color(), but to no avail. I could use print_html(), copy the output and paste it after the code-block, but this gets messy real quick, as I have to make changes to these tables a lot. Another solution I saw was specifying the table-layout in a .css-file, but this is also not great as I have a lot of tables in different sizes, so specifying the layout for all of the individually would be very tedious.

Any help would be appreciated.

shafee
  • 15,566
  • 3
  • 19
  • 47
DStuder
  • 45
  • 5
  • You could have a look at the `#| class-output:` chunk option to define one distinct css class for your tables. – Julian Apr 05 '23 at 13:15

1 Answers1

1

Try print_html along with chunk option output: asis.

---
title: Table style
format: html
---

```{r}
#| output: asis

library(huxtable)

t1 = matrix(c("",         "menu",   "",      "",     "", 
              "",         "",       "yes",   "no",   "", 
              "group",    1,        1,        4,      5,
              "",         2,        5,        1,      6,
              "",         "",       6,        5,      11),
            nrow = 5, byrow = T)

huxtable::as_hux(t1) |> 
  set_bottom_border(row = c(2,4), col = 2:5) |>
  set_bottom_border(row = c(1,5), col = c(3,4)) |>
  set_right_border(row = 2:5, col = c(2,4)) |> 
  set_right_border(row = c(3,4), col = c(1,5)) |> 
  merge_cells(row = 1, col = 2:5) |> 
  merge_cells(row = c(3,4), col = 1) |> 
  set_align(row = everywhere, col = everywhere, "center") |> print_html()
```

huxtable printed

shafee
  • 15,566
  • 3
  • 19
  • 47
  • 1
    Thanks a lot! This works very well for most tables. However, it seems like it disables callout-blocks. That is rather unfortunate, since as I have a few tables within callout-blocks, e.g. to highlight examples. Any ideas as to how I could make the callout-block behave normally? – DStuder Apr 06 '23 at 11:30
  • By dumb chance I found a`solution to my callout-block-problem: Setting `#| output: asis in the options, but NOT adding `print_html()` at the end spits out the huxtable in its original formatting and does not mess with the callout-block. Only downside is that it generates a random horizontal line above the table. – DStuder Apr 06 '23 at 14:44
  • @DStuder, I would suggest asking a separate question regarding the problem with callout-blocks and printing huxtables with reproducible examples. That would be helpful to test the problem and provide solutions if possible :) – shafee Apr 06 '23 at 15:00