简体   繁体   中英

How to Shrink Column Width and Table Size In Kable(type = rmarkdown)

I am making slides in rmarkdown, and when I use

 kable(tablename)

the columns adjust so the table fits the whole slide.

I want the columns to be a smaller fixed size somehow. Either by wrapping columns around the width of the text/numbers, or declaring a fixed width.

Also, I wouldn't mind shrinking the whole table to be a much smaller size.

I'd like to avoid using other packages and just want to know how to do this with kable.

I do this when kniting to .pdf by using latex commands and minipage package. I don't think you will have to install this.

\centering
\begin{minipage}{0.4\textwidth}
```{r}
Use your kable command here to create your first table

knitr::kable(data[c(rownum),],format = "latex")
```
\end{minipage}
\begin{minipage}{0.4\textwidth}
```{r}
Use your kable command here to create your second table

knitr::kable(data[c(rownum),],format = "latex")
```
\end{minipage}
\flushleft

the \\centering and \\flushleft commands are your preference and do what you would expect. The two minipage commands will put the tables side by side. you can place more than two byt will have to play around with the {0.4\\textwidth} part, which means allow table to occupy 0.4 of the text width.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM