23
votes

I'm using Rmarkdown to create a document. I want to include markdown tables, but they are all scaled to the width of the page. I'd like to specify a relative width of say... 40% for the table. I've tried various options associated with the following:

library(pander)
pandoc.table(head(cars))

library(xtable)
print(xtable(head(cars)), type="html")

library(knitr)
kable( head(cars), format="markdown")

Any ideas?

Thanks

1
Have you tried pander split.table option? There you can set the width of the tables - but I think you have to set it per hand or calculated by R... see: rapporter.github.io/pander/#table-and-cell-width - Julian
It does not depend on your markdown table, but rather on your LaTeX/CSS stylesheet. - daroczig

1 Answers

20
votes

If you're outputting an html document you need to modify the css. You can add this directly to the Rmd document:

<style type="text/css">
.table {

    width: 40%;

}
</style>