Setting page width in Knitr for md or HTML output

I have knitr to generate the output of my statistical analysis along with the numbers. My analysis has a number of levels marked with headings. To get a good html page with a table of contents aside, I use the "pander" (pandoc R package) to convert my .md file to html because knitr does not insert the table of contents in the html file.

Problem: when I use the pander, it creates a page with a fixed width (rather narrow), where my large numbers need to be scrolled left and right. Is there a way to change the page width .md or a direct pointer to display a page with automatic width settings (setting to any screen width).

I spent time searching for a solution: either you have knitr, and insert TOC, insert the width parameter into the r-code

```{r set-options, echo=FALSE, cache=FALSE} options(width=600) opts_chunk$set(comment = "", warning = FALSE, message = FALSE, echo = TRUE, tidy = FALSE, size="small") ``` 

or edit the pader output options, but no luck.

If anyone has a solution to the problem, I would really appreciate it.

+7
source share
2 answers

knitr does not apply to rendering knitr directly, and you can compile *.md into *.html via markdown package , for which knitr has a knit2html() wrapper function. To get the table of contents, you can add the toc option to markdown::markdownToHTML() , for example.

 library(knitr) knit2html('foo.Rmd', options = c('toc', markdown::markdownHTMLOptions(TRUE))) 
+12
source

To avoid scrolling, you can use out.width and out.height to determine the width and height of the graph in the final output file.

 ```{r fig.width=7, fig.height=6,out.width=250,out.height=400} plot(cars) ``` 
+1
source

All Articles