Reputation: 81
I am using RMarkdown to write reproducible reports, however, I am looking for guidance on how to change the justification on table/figure captions when using Kable?
Also, can you bold or italicize the Table 1: component of the caption?
knitr::kable(head(iris), 'latex', caption = 'Title of table',
booktabs = TRUE) %>%
kableExtra::kable_as_image()
This code will produce a generally nice looking table. However, I want to left-justify the title and bold the text "Table 1:" which automatically precedes my table caption.
Thanks for your help.
Upvotes: 2
Views: 4442
Reputation: 45027
You can use the LaTeX captions
package to customize your captions. For example, this document
---
output: pdf_document
header-includes:
- \usepackage[justification=raggedright,labelfont=bf,singlelinecheck=false]{caption}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r echo=FALSE}
knitr::kable(head(iris), caption = 'Title of table',
booktabs = TRUE)
```
produces this table output:
Alternatively, if you really want this in a screenshot file, use
library(knitr)
library(kableExtra)
kable(head(iris), format="latex", caption = 'Title of table',
booktabs = TRUE) %>%
as_image(file="~/temp/table.png",
latex_header_includes="\\usepackage[justification=raggedright,labelfont=bf,singlelinecheck=false]{caption}")
Upvotes: 8