Table 1

How to make row height smaller?

t<-mpg %>% tab_cells(hwy,displ) %>%
  tab_rows(manufacturer) %>% 
  tab_stat_mean() %>%
  tab_pivot() %>% 
  set_caption("Car Stats") %>% as_huxtable() 


t %>%
  set_col_width(1,.5) %>%
  set_row_height(.2) %>%
  theme_article()
Car Stats
#Total
manufactureraudihwyMean26.4 
displ2.54
chevrolethwy21.9 
displ5.06
dodgehwy18   
displ4.34

Table 2 (height=0.2)

mpg %>% tab_cells(hwy,displ) %>%
  tab_rows(manufacturer) %>% 
  tab_stat_mean() %>%
  tab_pivot() %>% 
  set_caption("Car Stats") %>% as_huxtable() %>% 
  set_col_width(1,.1)  %>%
  theme_article()->t

height(t)<-.2

t
Car Stats
#Total
manufactureraudihwyMean26.4 
displ2.54
chevrolethwy21.9 
displ5.06
dodgehwy18   
displ4.34

Table 3 (height=0.1 & no theme)

mpg %>% tab_cells(hwy,displ) %>%
  tab_rows(manufacturer) %>% 
  tab_stat_mean() %>%
  tab_pivot() %>% 
  set_caption("Car Stats") %>% as_huxtable() %>% 
  set_col_width(1,0.1) ->t

height(t)<-.1

t
Car Stats
#Total
manufactureraudihwyMean26.4 
displ2.54
chevrolethwy21.9 
displ5.06
dodgehwy18   
displ4.34

Table 3 (height=0.1 & no theme)

Theme has nothing to do with this…. Use padding parameters

mpg %>% tab_cells(hwy,displ) %>%
  tab_rows(manufacturer) %>% 
  tab_stat_mean() %>%
  tab_pivot() %>% 
  set_caption("Car Stats") %>% as_huxtable() %>% 
  theme_blue() %>%
  set_col_width(1,2.3) ->t

t %>%
    set_top_padding(.2) %>%
    set_bottom_padding(.2) %>% set_caption("This works...")
This works...
#Total
manufactureraudihwyMean26.4 
displ2.54
chevrolethwy21.9 
displ5.06
dodgehwy18   
displ4.34


Conclusion: make a custom function that defines your table structure, like this:

tset<-function(x){as_huxtable(x) %>% set_number_format(1) %>% 
    set_bold(row = 1, col = everywhere) %>% 
    set_bottom_border(row = 1, col = everywhere) %>% 
    set_bottom_border(row = dim(t)[1], col = everywhere) %>%
    set_top_padding(.2) %>%
    set_bottom_padding(.2) %>%   
    theme_article() }

 

mpg %>% tab_cells(hwy,displ) %>%
  tab_rows(manufacturer) %>% 
  tab_stat_mean() %>%
  tab_pivot() %>% 
  set_caption("Car Stats")  ->t

tset(t) %>% 
  set_col_width(1,1.5) %>% # column 1 is to be "1.5" units wide
  set_caption("Used function with `t` ")
Used function with `t`
#Total
manufactureraudihwyMean26.4
displ2.5
chevrolethwy21.9
displ5.1
dodgehwy18.0
displ4.3

 

tset(t) %>% 
  set_col_width(1,.2) %>% # set additional parameters beyond the tset() function
  set_col_width(2,.3) %>%
  huxtable::theme_striped() %>%
  set_caption("Used function with `t` with narrower column width ")
Used function with `t` with narrower column width
#Total
manufactureraudihwyMean26.4
displ2.5
chevrolethwy21.9
displ5.1
dodgehwy18.0
displ4.3