4

This is a very general question. I created a few tables in an R markdown using the gt package. I was wondering how to scale down the table so it fits into the PDF created when I knit the markdown script. I have the following code for the table:

DEGs %>%
  filter(FC==2 & package=="edgeR") %>%
  select(-Dataset_label, -FC, -FDR, -Condition_1, -Condition_2, -package, -FullGeneBody.Down_genes, -FullGeneBody.Up_genes) %>%
  gt() %>%
  tab_options(
    container.width = pct(85),
    container.overflow.x = T,
    table.align = "center",
    table.width = pct(85),
    table.layout = "auto"
  )%>%
  tab_header(
    title = "DEHP and Pb 5 Month ",
    subtitle = glue("|FC| > {DEGs$FC[5]} and FDR < {DEGs$FDR[5]}")
  ) %>%
  fmt_number(
    columns = comparison
  ) %>%
  #fmt(
    #columns = c(Condition_Name_1, Condition_Name_2, Condition_1_GM_Numbers, Condition_2_GM_Numbers)
    
  #)%>%
  fmt_number(
    columns = c(ExonCollapsed.Down_genes, ExonCollapsed.Up_genes)
    
  ) %>%
  cols_label(
    comparison="Comp", 
    Condition_Name_1="Condition 1", 
    Condition_Name_2="Condition 2",
    Condition_1_GM_Numbers="Condition 1 #s", 
    Condition_2_GM_Numbers="Condition 2 #s", 
    ExonCollapsed.Down_genes="Down Genes", 
    ExonCollapsed.Up_genes="Up Genes"
    )

As you can see I tried using table.align, table.width etc. to try to resize the table, but none those settings seem to affect the table in the actual PDF.

Thanks for the help.

Edit: Someone asked for me to make the code a reproducible example, and I am uncertain if I can do this with the built-in datasets. i think some of the confusion is because I did not make it clear what happens when I knit the markdown to PDF. So if I just run the code above I get an output like the following: Result of running the code chunk with the above code

It is fine with a scroll bar appearing allowing one to see the entire table by scrolling. However when I knit to a PDF I get the following:

Result of knitting the R Markdown to a pdf the code chunk with the above code

As you can hopefully see the table is completely cut off in the PDF.

(Note: to see the images right click on the icon and click open in new tab. My fault I may have linked the images wrong)

dengel1392
  • 53
  • 7
  • https://gt.rstudio.com/reference/tab_options.html – QHarr May 26 '21 at 02:06
  • Yes I looked at that, but did not see an appropriate answer. – dengel1392 May 26 '21 at 05:09
  • 3
    It would be easier to help if you create a small reproducible example along with expected output. Read about [how to give a reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah May 26 '21 at 05:21
  • 2
    There is a comment at https://github.com/rstudio/gt/issues/937: the tab_options are reflected in the HTML document, but not PDF – Susan Switzer Oct 11 '22 at 19:29

0 Answers0