Is it possible to change the column width using kable without kableExtra?
If you have raw HTML or LaTeX code in the data, remember to put escape = FALSE
in kable()
to avoid escaping of special characters.
```{r}
library(kableExtra)
kable(df.table, "latex", booktabs = TRUE, escape = FALSE) %>%
kable_styling(full_width = FALSE) %>%
column_spec(4, width = "18em")
```
Scale kable table to fit page width
One option is to use kable_styling
from the kableExtra
package. The option latex_options="scale_down"
will fit the table within the paper margins. See the vignette for detailed examples on all of the formatting options.
---
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(knitr)
library(kableExtra)
```
```{r}
kable(cbind(mtcars[1:5,], mtcars[1:5,]))
```
```{r}
kable(cbind(mtcars[1:5,], mtcars[1:5,]), format="latex", booktabs=TRUE) %>%
kable_styling(latex_options="scale_down")
```
Kable column width in html rmarkdown
You'll need to set width_min
in column_spec
. I think 3in
is already enough for your column 1 in the example.
If you really need 10in
for some reason, you can add scroll_box()
to enable x-axis scrolling in the table (not included in my answer).
kable(df, col.names = colnames(df), escape = F) %>%
kable_styling(full_width = T) %>%
column_spec(1, width_min = '3in')
Related Topics
Transform Only One Axis to Log10 Scale with Ggplot2
How to Add Another Layer/New Series to a Ggplot
Figure Captions, References Using Knitr and Markdown to HTML
Highlight (Shade) Plot Background in Specific Time Range
How to Display the Median Value in a Boxplot in Ggplot
How to Get Last Subelement of Every Element of a List
Hollow Histogram or Binning for Geom_Step
How to Remove Na from Facet_Wrap in Ggplot2
How to Play Birthday Music Using R
Pandoc Insert Appendix After Bibliography
Alternatives to Nested Ifelse Statements in R
Subtract a Constant Vector from Each Row in a Matrix in R