21

How can I create a short caption in kable?

library(dplyr)
library(knitr)
library(kableExtra)

df <- data.frame( X = sample(letters, 10), y = runif(10), z = sample(10:20, 10))

kable(df,
      booktabs = TRUE,
      caption = "This caption is way too long and doesnt look good when formatted in the Table of Contents.  What you really need here is a much shorter caption so that your eyes dont go crazy trying to figure out what information the author is trying to convey.  Often there is too much information in the caption anyway so why not shorten it?.",
      escape = FALSE,
      format = 'latex') %>%
  kable_styling(latex_options = c("striped", "hold_position"))
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
Caddisfly
  • 1,290
  • 6
  • 24
  • I'm voting to close this question as off-topic because "This is not a question". – Andy Hayden May 04 '18 at 01:08
  • 2
    Welcome to Stack Overflow! Unfortunately, this question as it currently stands will be closed, because it is not an answerable question. If you want to document information for others to see, the proper way to do so is by posting your problem in the "Question" field, then posting the solution as a [self-answer](/help/self-answer). Otherwise, we appreciate your adding to the overall knowledge base that is Stack Overflow! – gparyani May 04 '18 at 02:29
  • 11
    I absolutely agree with @gparyani. The current post is a great Q&A, and the only problem is that the Q&A are together. It will be perfect if you could split them! And thanks Caddisfly for sharing the knowledge! BTW, to those who downvoted this post: I just want to say that there could be a better way to help the OP... – Yihui Xie May 04 '18 at 17:52

1 Answers1

24

I found a very obscure reference to this option for kable.

To make your caption short simply use e.g., caption.short = "This is a short caption".

library(dplyr)
library(knitr)
library(kableExtra)
df <- data.frame( X = sample(letters, 10), y = runif(10), z = sample(10:20, 10))

kable(df,
      booktabs = TRUE,
      caption = "This caption is way too long and doesnt look good when formatted in the Table of Contents.  What you really need here is a much shorter caption so that your eyes dont go crazy trying to figure out what information the author is trying to convey.  Often there is too much information in the caption anyway so why not shorten it?.",
      caption.short = "This is a shorter caption.",
      escape = FALSE,
      format = 'latex') %>%
  kable_styling(latex_options = c("striped", "hold_position"))
Caddisfly
  • 1,290
  • 6
  • 24