2

I have been using printr to render nice tables in the markdown output.

I have got a nice table in the rmarkdown pdf output.

table(sample(LETTERS, 200, replace = TRUE))

enter image description here

However, in this case, the output is not a nicer fit to the output.

table(sample(stringi::stri_rand_strings(20, 3), 200, replace = TRUE))

enter image description here

How to print the table into multiple lines if the width is exceeding the page width?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Prradep
  • 5,506
  • 5
  • 43
  • 84
  • You may check [here](https://stackoverflow.com/questions/15385696/how-to-adjust-the-output-width-of-rstudio-markdown-output-to-html) – akrun Aug 05 '17 at 13:58
  • I tried different values (eg: `options(width = 10)`) and it did not work for the tables in pdf output. – Prradep Aug 05 '17 at 14:01
  • If you can use xtable... https://stackoverflow.com/questions/16507191/automatically-adjust-latex-table-width-to-fit-pdf-using-knitr-and-rstudio – Roman Luštrik Aug 05 '17 at 14:03
  • I am getting the latex code as output instead of a table. – Prradep Aug 05 '17 at 14:13
  • 1
    `options(width)` won't do anything in this case. I guess there isn't a solution unless you reorganize your table to make it narrower (e.g. manually split the table into multiple lines and create one table per line). – Yihui Xie Aug 05 '17 at 19:04
  • Thanks @Yihui. I will consider it transposing before printing. Also, I observed it is the same with the code(a line having more length than page width) in the chunks. Does this have any workaround(s)? – Prradep Aug 05 '17 at 19:44

0 Answers0