Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

R Markdown - Knitr - Help to Align Table Left in HTML Output

$
0
0

I am experimenting with Knitr/KableExtra in RStudio but cannot make my tables use the full width of the web browser or control the table alignment on the screen.

Below is an example of the code where as per the kable_styling documentation, I have tried force the table to align to the left of the screen but in the html output, the table is always centered. It sees that there is an invisible margin to the left that I can't use. The problem arises when I have a table with more fields....the large margin on the left remains, forcing the table to extend to the right of the screen and generate a horizontal scrollbar - very annoying and ugly.

Is there some way I can use the space on the left margin or force the table to align truly to the left?

Please see the image attached for an example of the issue.

example

Thanks!

---
title: "Untitled"
author: "ME"
date: "2/4/2020"
output: html_document
---

```{r setup, include=FALSE}
library(kableExtra)

knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
x_html <- knitr::kable(head(mtcars), "html")
kable_styling(x_html, "striped", position = "left", font_size = 7)
```


Viewing all articles
Browse latest Browse all 201839

Trending Articles