2
votes

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?

1
FWIW if you keep the tex output, and knit the rmd document by hand, you'll see that the rmd->md step is OK, but md->tex escapes latex commands. So I guess it's a pandoc issue. You could perhaps work with a Rnw source file instead, if there's no easy workaround.baptiste
Is there any answer for this?user3022875
@user3022875 I posted a work around as an answer, but won't mark it as answered since it doesn't really fix the specified problem of removing the scalebox text from the pdf output.TBT8

1 Answers

0
votes

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.