I want to make my table caption in bold but can't seem to find the option for it.
My code is (in a rmarkdown document):
kable(head(iris), caption = 'I want this in Bold') %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
The output is:
Does this markdown-oriented solution work for you?
```{r, results='asis'}
kable(head(iris), caption = '**I want this in Bold**') %>%
kableExtra::kable_styling(bootstrap_options = c("striped", "hover", "condensed","responsive"))
```
for html-output this should work:
```{r, results='asis'}
kable(head(iris), caption = '<b>I want this in Bold</b>', format = 'html') %>%
kableExtra::kable_styling(bootstrap_options = c("striped", "hover", "condensed","responsive"))
```
for pdf-output this should work:
```{r, results='asis'}
kable(head(iris), caption = '\\textbf{I want this in Bold}', format = 'latex') %>%
kableExtra::kable_styling(bootstrap_options = c("striped", "hover", "condensed","responsive"))
```
Related
I have tried many techniques (mostly around editing the raw HTML passed to caption in order to change the size of a title (aka caption) when using KableExtra.
Minimal Reproducible Example
Here's a simple example:
library(knitr)
library(kableExtra)
iris %>%
head %>%
kable(
table.attr = "style = \"color: black;\"",
caption = "<span style='font-size:20'>A lovely title</span>"
) %>%
kable_styling("striped", full_width = T)
But the title size doesn't change:
Span accepts CSS font-size in 3 different ways. Run the following examples to see them in action:
Pixels
library(knitr)
library(kableExtra)
iris %>%
head %>%
kable(
table.attr = "style = \"color: black;\"",
caption = "<span style='font-size:20px'>A lovely title</span>"
) %>%
kable_styling("striped", full_width = T)
Percent
iris %>%
head %>%
kable(
table.attr = "style = \"color: black;\"",
caption = "<span style='font-size:200%'>A lovely title</span>"
) %>%
kable_styling("striped", full_width = T)
"small", "large" etc.
iris %>%
head %>%
kable(
table.attr = "style = \"color: black;\"",
caption = "<span style='font-size:small'>A lovely title</span>"
) %>%
kable_styling("striped", full_width = T)
Read more here
I need to remove the name of variables in a table produced with kable and that I will export to pdf
kable(x, col.names = NULL) it works when the output is in html format, but when the output is pdf it does not compile and throws an error: "add_intent_latex..."
Try this solution, I prepared a template for you:
---
title: "Hello World"
output:
pdf_document:
latex_engine: xelatex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, include = FALSE}
library(kableExtra)
my_data <- mtcars[1:5, 1:6]
my_table <- my_data %>%
kbl(caption = "without col.names", col.names = NULL) %>%
kable_styling(bootstrap_options = c("striped", "hover"), latex_options = "hold_position")
my_table1 <- my_data %>%
kbl(caption = "with col.names") %>%
kable_styling(bootstrap_options = c("striped", "hover"), latex_options = "hold_position")
```
```{r}
my_table
```
```{r}
my_table1
```
Well I have a table in Rmarkdown but since I write the document in Greek I want also the Table word to be printed in Greek
```{r name, echo=FALSE,results='asis'}
kablegr %>%
kbl(caption = "**_Πίνακας_**") %>%
kable_classic(full_width = F, html_font = "Cambria")%>%
column_spec(1, bold = TRUE, border_right = TRUE, color = "black", background = "lightgrey")
```
what I want is instead o Table to print Πίνακας in each table of my document
Table: --> Πίνακας:
OPTION 1
This a solution that keeps the numbering automatically (following this answer. Nonetheless, I had to suppress the bold face.
---
title: "Untitled"
author: "bttomio"
date: "5/10/2021"
output: html_document
---
```{r, include=F}
library(captioner)
tables <- captioner(prefix = "Πίνακας")
```
```{r tab1, echo=FALSE}
library(kableExtra)
mtcars %>%
kbl(caption=tables("tab1", "Table Caption")) %>%
kable_classic(full_width = F, html_font = "Cambria")%>%
column_spec(1, bold = TRUE, border_right = TRUE, color = "black", background = "lightgrey")
```
```{r tab2, echo=FALSE}
library(kableExtra)
mtcars %>%
kbl(caption=tables("tab2", "Table Caption")) %>%
kable_classic(full_width = F, html_font = "Cambria")%>%
column_spec(1, bold = TRUE, border_right = TRUE, color = "black", background = "lightgrey")
```
-output
OPTION 2
You could try this (fig_caption: no in your YAML header):
---
title: "Untitled"
author: "bttomio"
date: "5/10/2021"
output:
html_document:
fig_caption: no
---
```{r name, echo=FALSE,results='asis'}
library(kableExtra)
mtcars %>%
kbl(caption = "**_Πίνακας_**") %>%
kable_classic(full_width = F, html_font = "Cambria")%>%
column_spec(1, bold = TRUE, border_right = TRUE, color = "black", background = "lightgrey")
```
-output
This is presumably related to latex kable side-by-side tables "Not in outer par mode" but the solution identified by the author, to use latex_options = c("Hold_position") is not changing the outcome for me when I try to knit to PDF. The author's full comment reads:
I got the tables to display side-by-side by adding kable_styling(latex_options = c("striped", "Hold_position")).
Here is a minimal example that works fine:
---
title: "Example Document"
date: "Last compiled on `r format(Sys.time(), '%d %B, %Y at %H:%M ')`"
output: pdf_document
---
```{r setup, include=FALSE, echo=FALSE}
library(tidyverse)
library(kableExtra)
```
``` {r species}
kable(caption = "Species",
starwars %>%
count(species) %>%
filter(n > 1)
) %>% kable_styling(latex_options = c("striped", "Hold_position"))
```
``` {r planet}
kable(caption = "Homeworld",
starwars %>%
count(homeworld) %>%
filter(n > 1)
)%>% kable_styling(latex_options = c("striped", "Hold_position"))
```
When I use knitr::kables to combine them into a pair of side-by-side tables, I can run the code chunk and knit to HTML just fine, but I'm still getting a "not in outer par mode" error:
! LaTeX Error: Not in outer par mode.
Error: LaTeX failed to compile 10_knit_doesnt.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See 10_knit_doesnt.log for more info.
Execution halted
The actual code chunk is this:
``` {r side by side}
knitr::kables(list(
kable(caption = "Species",
starwars %>%
count(species) %>%
filter(n > 1)
) %>% kable_styling(),
kable(caption = "Homeworld",
starwars %>%
count(homeworld) %>%
filter(n > 1)
) %>% kable_styling()
)
) %>% kable_styling(latex_options = c("striped", "Hold_position"))
```
I've tried moving the styling (kable_styling(latex_options = c("striped", "Hold_position")) ) into the individual tables, but that doesn't seem to have any impact.
knitr::kables(list(
kable(caption = "Species",
starwars %>%
count(species) %>%
filter(n > 1)
) %>% kable_styling(latex_options = c("striped", "Hold_position")),
kable(caption = "Homeworld",
starwars %>%
count(homeworld) %>%
filter(n > 1)
) %>% kable_styling(latex_options = c("striped", "Hold_position"))
)
) %>% kable_styling()
Can I knit to PDF while using side-by-side tables?
Following this example, here's what I have
# iris
This section is about the iris dataset
```{r, echo=FALSE, message=FALSE, warning=FALSE}
kable(head(iris[, 1:2]), format = "html") %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE, position = "float_right")
```
# mtcars
This section is about the mtcars dataset
```{r, echo=FALSE, message=FALSE, warning=FALSE}
kable(head(mtcars[, 1:2]), format = "html") %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE, position = "float_right")
```
But the output looks like this:
How do make the mtcars section appear below the iris section?
I guess kableExtra doesn't offer such functionality yet.
You can however resolve to html, and do the following with little effort:
---
title: "hi"
author: "me"
date: "March 23, 2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(knitr)
library(kableExtra)
options(knitr.table.format = "html")
```
```{r}
kable(head(iris[, 1:2])) %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE, position = "float_right")
```
# iris
This section is about the iris dataset.
This could be a whole paragraph.
<p style="clear: both"></p>
```{r}
kable(head(mtcars[, 1:2])) %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE, position = "float_right")
```
# mtcars
This section is about the mtcars dataset
The relevant bit is <p style="clear: both"></p>
Put text after the table, and also add line breaks. Since the output is in html, it seems like it doesn't know how large the table is, and uses simple HTML tags to wrap around. One solution, wrap it in a table with 100% width:
<table style="width:100vw">
```{r, echo=FALSE, message=FALSE, warning=FALSE}
kable(head(iris[, 1:2]), format = "html") %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE, position = "float_right")
```
# iris
This section is about the iris dataset.
</table>
<table style="width:100vw">
```{r, echo=FALSE, message=FALSE, warning=FALSE}
kable(head(mtcars[, 1:2]), format = "html") %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE, position = "float_right")
```
# mtcars
This section is about the mtcars dataset.
</table>