hughjonesd / huxtable

An R package to create styled tables in multiple output formats, with a friendly, modern interface.
http://hughjonesd.github.io/huxtable
Other
321 stars 28 forks source link

Resize table to fit on a page #243

Closed hufdesf closed 1 year ago

hufdesf commented 1 year ago

Hi!!! I am trying to create a table with a lot of information and I need to fit this table into a single page. The table is half done and already doesn't fit on a page. See pls attached file. Any suggestions are welcome!


title: "TEST"

output: pdf_document: default


\pagenumbering{gobble} \captionsetup{labelformat=empty}

knitr::opts_chunk$set(echo = FALSE, warning = FALSE, tabular.environment = 'longtable')
library(huxtable)
library(dplyr) 

table_1 <- huxtable(Energiekennzahlen = c("","","",""), Mittlere = c("0°C / +2°C", "+2°C / +4°C", "+4°C / +6°C", "+5°C / +7°C" ),
                     Verdampfungstemp=c("-6 °C", "-4 °C", "-4 °C", "-3 °C"),
                     Möbellänge = c("[kWh/d]", "[kWh/d]", "[kWh/d]", "[kWh/d]"),
                    mm1250 = c("","","",""),
                    DEC = c("1,28", "0,78", "0,78", "0,78"),
                    REC = c("17,68", "13,97", "13,20", "12,06"),
                    TEC = c("18,96", "14,75", "13,98", "12,84"),
                    TDA = c("2,24", "2,24", "2,24", "2,24"),
                    TEC_TDA = c("8,47", "6,59", "6,25", "5,74"),
                    mm1875 = c("","","",""),
                    DEC_ = c("1,28", "0,78", "0,78", "0,78"),
                    REC_ = c("17,68", "13,97", "13,20", "12,06"),
                    TEC_ = c("18,96", "14,75", "13,98", "12,84"),
                    TDA_ = c("2,24", "2,24", "2,24", "2,24"),
                    TEC_TDA_ = c("8,47", "6,59", "6,25", "5,74"),
                    mm2500 = c("","","",""),
                    DEC_3 = c("1,28", "0,78", "0,78", "0,78"),
                    REC_3 = c("17,68", "13,97", "13,20", "12,06"),
                    TEC_3 = c("18,96", "14,75", "13,98", "12,84"),
                    TDA_3 = c("2,24", "2,24", "2,24", "2,24"),
                    TEC_TDA_3 = c("8,47", "6,59", "6,25", "5,74"),
                    mm3750 = c("","","",""),
                    DEC_2 = c("1,28", "0,78", "0,78", "0,78"),
                    REC_2 = c("17,68", "13,97", "13,20", "12,06"),
                    TEC_2 = c("18,96", "14,75", "13,98", "12,84"),
                    TDA_2 = c("2,24", "2,24", "2,24", "2,24"),
                    TEC_TDA_2 = c("8,47", "6,59", "6,25", "5,74"),
                    mm1875_K = c("","","",""),
                    DEC_1 = c("1,28", "0,78", "0,78", "0,78"),
                    REC_1 = c("17,68", "13,97", "13,20", "12,06"),
                    TEC_1 = c("18,96", "14,75", "13,98", "12,84"),
                    TDA_1 = c("2,24", "2,24", "2,24", "2,24"),
                    TEC_TDA_1 = c("8,47", "6,59", "6,25", "5,74")
                    )

 table_1_t<- t(table_1)
 table_1_t[1:nrow(table_1_t),][[1]] <- c(" \\vtop{\\hbox{\\strut 1. Energiekennzahlen /}\\hbox{\\strut energy datas: }}",
                           "\\vtop{\\hbox{\\strut Mittlere Warenraumtemperatur /}\\hbox{\\strut average case temperaturese: }}",
                           " \\vtop{\\hbox{\\strut Verdampfungstemp. / }\\hbox{\\strut evaporating temp.:}}",
                           " \\vtop{\\hbox{\\strut Möbellänge /}\\hbox{\\strut cabinet length:}}",
                           "1250 mm",
                           "DEC", "REC", "TEC", "TDA", "TEC/TDA",
                           "1875 mm",
                           "DEC", "REC", "TEC", "TDA", "TEC/TDA",
                           "2500 mm",
                           "DEC", "REC", "TEC", "TDA", "TEC/TDA",
                           "3750 mm",
                           "DEC", "REC", "TEC", "TDA", "TEC/TDA",
                           "1875 mm(K)",
                           "DEC", "REC", "TEC", "TDA", "TEC/TDA"
                           )

 rows_size_table_1 <- nrow(table_1_t)
 cols_size_table_1_t <- length(colnames(table_1_t))

   #set_tabular_environment(scale)
   #print_latex(table_1_t, scalebox = 0.7)
   set_number_format(table_1_t,NA)  %>%
   set_background_color(odds,everywhere, "grey70")  %>%
   set_background_color(evens,everywhere,"white") %>% 
   set_escape_contents(everywhere,value = FALSE)  %>%
   set_bold(row = 2, col = 2:5) %>%
   set_font_size(8) %>%   
  set_bold(row = 3, col = 2:5) %>%  
  set_bold(row = 1, col = 1) %>%
  set_bold(row = c(5,11,17,23), col = 1) %>%   
  set_align(row=1, col=1, "left") %>%    
  set_right_border(row = 1:rows_size_table_1 , col = cols_size_table_1_t, value = 0.9) %>% 
  set_left_border(row = 1:rows_size_table_1, col = 1, value = 0.9) %>%
  set_top_border(row=1,col=everywhere, value = 0.9) %>%
  set_bottom_border(row= rows_size_table_1,col=everywhere,value = 0.9) %>%
  set_right_border(row = 2:rows_size_table_1 , col = 1, value = 0.7) %>%   
  set_caption("\\Large \\textbf{ Title here}") %>%
  set_width(1.05) %>%  
  set_height(value=0.01)  %>% 
  set_caption_pos("topcenter")  %>% 
  set_position("center") 
hughjonesd commented 1 year ago

Is this a bug report? If not, then why are you posting it here?

Update: to be clear, it may be that there's a legit bug lying under this heap of code, so I'm being kind to you. But if you're just hoping for help requests, and haven't bothered to read what was spelled out to you at the start of this bug report, then I am gonna be very annoyed with you.

hufdesf commented 1 year ago

The question is related to this post: https://github.com/hughjonesd/huxtable/issues/96 I am not sure if it is a bug or not but I could not solve my problem reading this post so I just posted it here because I think it is a related problem. But well if this post annoyed you I am sorry that was not the intention. I guess let's delete it then

hughjonesd commented 1 year ago

Yeah, the bug report template is pretty clear about this. Unless you can actually say what the issue is, and provide a minimal example, then you are cluttering up github issues with help requests. This is not the place for that. If you've got more info on issue 96 (not "post", this is not a forum), then add it there.