Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Markdown - xtable with longtable and scalebox outputs scalebox value

I am creating a PDF document with with rmarkdown and knitr. Below is an example code chunk. When knitting to PDF it prints the scalebox value to the PDF, which I don't want. My actual table is much wider so using the scalebox argument is necessary.

```{r, results = 'asis', echo = FALSE, message = FALSE, warning=FALSE}

    x <- matrix(rnorm(1000), ncol = 10)
    x.big <- xtable(x)

    print.xtable(x.big, hline.after=c(-1), tabular.environment = "longtable", scalebox = 0.7)

    ```

Image of scalebox text output

This only happens when using the longtable tabular environment. Running the same code chunk with the standard tabular environment doesn't output the scalebox info. I've tried setting every comment argument in the print.xtable function and the r code chunk to FALSE but with no luck.

How can I output my PDF file without that scalebox text being printed?

like image 492
TBT8 Avatar asked Dec 18 '25 12:12

TBT8


1 Answers

I haven't found a way to get around the scalebox issue. What I ended up doing was using was the size argument in print.xtable instead. Below is a sample function where size is an integer representing the desired size of the font.

outputXtableTest <- function( df, size){

  sizeNew = paste0("\\fontsize{", size,"pt}{", size+1, "pt}\\selectfont") 

  print.xtable(
             df, hline.after=c(-1,0, 1:nrow(table)),
             tabular.environment = 'longtable', 
             floating = FALSE, size = sizeNew
            )
}

See this post for more information.

like image 121
TBT8 Avatar answered Dec 21 '25 04:12

TBT8