15

LaTeX has the ability to add notes to the bottom of a table using tablenotes, so it seems like kable might be able to easily implement this -- or maybe it already does, but I can't find any mention of this capability.

For example: Table notes at the bottom of a table

jflournoy
  • 763
  • 1
  • 8
  • 23
  • 1
    You cannot, as [Pandoc's markdown](http://johnmacfarlane.net/pandoc/README.html#tables) does not support this feature. You can add the notes below the table separately. – daroczig Jan 13 '15 at 23:10
  • 1
    If you're willing to use `xtable` instead of `kable` to create your table, then [this SO answer](http://stackoverflow.com/a/9356118/496488) might provide a solution for you. – eipi10 Jan 04 '16 at 22:16
  • @eipi10: would xtable work for html output (with the notes)? – Fernando Hoces De La Guardia Aug 14 '16 at 20:47
  • @FernandoHocesDeLaGuardia, you can get html output like this `print(xtable(mtcars), type='html')`. I assume you can add notes in a similar way to Latex output, but I haven't tried it. – eipi10 Aug 14 '16 at 21:51
  • @eipi10 I tried the example in the link , but the note comes up in the first row once rendered (and the last on raw html in the console) – Fernando Hoces De La Guardia Aug 15 '16 at 16:54

1 Answers1

21

You can actually do exactly this using Hao Zhu's awesome kableExtra package! As follows:

library(knitr)
library(kableExtra)
dt <- mtcars[1:5, 1:4]

# LaTeX Table
 kable(dt, format = "latex", booktabs = T) %>%
   kable_styling() %>%
   add_footnote("Footnote 1", notation="alphabet")

enter image description here

Check out the GitHub repository for the full scope of everything kableExtra can do. It greatly extends the functionality of tables within both LaTeX and HTML with loads of extra features.

Grace Mahoney
  • 485
  • 1
  • 7
  • 14
  • The 'a' describes a specific cell, Siberian husky. Is it possible also insert an 'a' in a cell as per the table of the question? Thanks! – Rafael Mar 21 '20 at 13:58
  • To insert a superscript footnote number/letter/symbol in the row label, you can manually change the row name and add the appropriate notation as in `Datsun 710$^a$` for a `notation = alphabet` footnote. The dollar signs turn "math mode" on and off and the carrot ^ tells latex to superscript what follows. – Omar Wasow Jun 12 '21 at 18:10
  • For more on manually adding footnote marks to row labels, see Table Footnote section of manual: http://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf – Omar Wasow Jun 12 '21 at 18:20