The table width is being determined by the last footnote, which is wider than the table itself, so latex adds more space to the right when creating the table. Adding \n
within the footnote text to create a linebreak doesn't work in the latex conversion. Also, kableExtra
has a linebreak
function, which is intended for generating linebreaks in latex tables, but I wasn't able to get that to work within the footnote
function either.
After looking at the latex vignette for kableExtra
, I see there's an option for putting footnotes in a ThreePartTable
frame. Below is a complete rmarkdown example document. Note that I've commented out latex_options="scale_down"
, which will actually "scale up" the size of your table if its default width is less than the full width of the margins.
---
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r}
library(knitr)
library(kableExtra)
```
```{r}
kable(mtcars[1:9, 1:4], #col.names = names_spaced,
caption="Without ThreePartTable", row.names=FALSE, align=c("l",rep("r",3)),
format="latex", booktabs=TRUE) %>%
#kable_styling(latex_options="scale_down") %>%
column_spec(1,width = "1in") %>%
column_spec(2,width = "0.4in") %>%
column_spec(3,width = "0.4in") %>%
column_spec(4,width = "0.4in") %>%
add_indent(c(3:9)) %>%
add_header_above(header="Header") %>%
footnote(c("Source; 2000 Census",
"Source: 2010 Census",
"Really long footnote that increases the width of the table."))
```
```{r}
kable(mtcars[1:9, 1:4], #col.names = names_spaced,
caption="With ThreePartTable", row.names=FALSE, align=c("l",rep("r",3)),
format="latex", booktabs=TRUE) %>%
#kable_styling(latex_options="scale_down") %>%
column_spec(1,width = "1in") %>%
column_spec(2,width = "0.4in") %>%
column_spec(3,width = "0.4in") %>%
column_spec(4,width = "0.4in") %>%
add_indent(c(3:9)) %>%
add_header_above(header="Header") %>%
footnote(c("Source; 2000 Census",
"Source: 2010 Census",
"Really long footnote that increases the width of the table."),
threeparttable=T)
```
And the output document:

