简体   繁体   中英

Wrapping footnote to second line to fit table in kable (LaTeX .Rmd)

I'm wondering if there is a way I can force a footnote to fit the width of a table (and wrap to a second line) using kable in R (I'm knitting .Rmd to PDF so the format is latex). I've used both add_footnote() and footnote() . The add_footnote function will actually wrap a footnote to a second line if it extends beyond the width of the table, but it also forces the use of superscripts (which for this sake is something I can't have in my table). footnote gives me the option to remove the superscript but I'm not sure how to get it to match the formatting of add_footnote and wrap footnotes that are wider than the table to a second line. Another solution would be to remove the superscripts from add_footnote

\captionsetup[table]{labelformat=empty}
```{r packs}
library(pacman)
p_load(tidyverse,knitr,kableExtra,janitor)

mydf <-data_frame(x=1:4,y=2:5,z=3:6)

fn1='This the footnote 1'
fn2='This is footnote 2 and is much longer'

mydf %>%
  kable(format='latex',booktabs=T,
        col.names=c('X','Y','Z'),
        caption=c('This method stretches', 'my table out in an ugly way')) %>%
  kable_styling(latex_options = c('hold_position')) %>%
  footnote(general=c(fn1, fn2),general_title="")

mydf %>%
  kable(format='latex',booktabs=T,
        col.names=c('X','Y','Z'),
        caption=c('This method ruins my title', 'and left justifies my table')) %>%
  kable_styling(latex_options = c('hold_position')) %>%
  footnote(general=c(fn1, fn2),general_title="",threeparttable = T)

mydf %>%
  kable(format='latex',booktabs=T,
        col.names=c('X','Y','Z'),
        caption=c('This is pretty close to perfect', 'if I could remove the superscripts')) %>%
  kable_styling(latex_options = c('hold_position')) %>%
  add_footnote(c(fn1, fn2))
```

A screenshot of the knitted PDF: 在此处输入图片说明

Below is the notation="none" option @hao suggested. It is center-justified.

mydf %>%
  kable(format='latex',booktabs=T,
        col.names=c('X','Y','Z'),
        caption=c('Notation="none"') %>%
  kable_styling(latex_options = c('hold_position')) %>%
  add_footnote(c(fn1, fn2), notation="none")

在此处输入图片说明

按照@hao 的建议设置threeparttable = TRUE对我有用:

add_footnote(c(fn1, fn2), threeparttable = TRUE) 

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