I knit code below. and this is the output. long in kbl(0 for html, I want to have the term "continued" in flextable for docx too. what is the trick?
---
title: ''
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r echo=FALSE, message=FALSE, warning=FALSE}
library(flextable)
library(dplyr)
library(ggplot2)
mpg[, 1:4] %>%
flextable() %>%
set_caption(caption = "my caption") %>%
set_table_properties(width = 1, layout = "autofit")
```
Related
Using the following code, I get a pdf with the plot in desired place.
---
title: "Stackquestion"
author: "Author"
date: "`r Sys.Date()`"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(kableExtra)
```
## R Markdown
Whatever text
```{r cars}
dt <- mtcars[1:5, 1:6]
kbl(dt, booktabs = T)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
But when adding kable_styling the plot is placed in wrong position. Is there a way to get around this?
---
title: "Stackquestion"
author: "Author"
date: "`r Sys.Date()`"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(kableExtra)
```
## R Markdown
Whatever text
```{r cars}
dt <- mtcars[1:5, 1:6]
kbl(dt, booktabs = T) %>%
kable_styling(full_width = F) %>%
add_header_above(c("Some text also goes here"))
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
You can use the latex_options in kable_styling:
kable_styling(full_width = F, latex_options = "HOLD_position")
I would like to set each value of a column in a datatable as an internal link to a different slide. Below is what I have tried but the link is not selectable.
---
title: "Example"
output: slidy_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r message=FALSE, warning=FALSE, include=FALSE}
library(DT)
library(tidyverse)
```
## Table
```{r carstab, echo = FALSE}
datatable(mtcars %>% rownames_to_column(var = "plot") %>% mutate(plot = ("[plot](#/plot)")),escape = TRUE)
```
## plot
```{r plot, echo = TRUE}
plot(mtcars)
```
mutate(plot = ("[plot](#/plot)")) does not work because the markdown code [plot](#/plot) will not be translated to HTML. Its a character.
You want something like <a href = '#(slide_number)'> This is a link </a> in your DT cells.
You could generate such links using paste0():
datatable(
mtcars %>%
mutate(
plot = 3,
plot = paste0("<a href = '#(", plot, ")'>link</a>"),
), escape = FALSE
)
The plot column in your DT now contains valid links to slide 3 (modify the first instance of plot in mutate() accordingly to link to different slides).
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
```
I'm unable to scale a table using scale_down option from kableExtra if previously I modify the page size.
EDIT: I've rewritten the markdown file to make it more reproducible as suggested:
---
title: "test"
documentclass: article
output:
pdf_document:
fig_caption: yes
keep_tex: true
pandoc_args: --listings
latex_engine: xelatex
header-includes:
- \usepackage{float}
- \usepackage{graphicx}
- \usepackage{subfig}
- \usepackage{xcolor}
---
```{r setup, include=F}
library(knitr)
library(kableExtra)
library(tidyverse)
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, include = T, results='hide')
```
\clearpage
\eject \pdfpagewidth=297mm \pdfpageheight=210mm
```{r test, fig.show='asis', results='asis'}
do.call(cbind.data.frame, rep(mtcars, 10)) %>%
as.data.frame %>%
head(n = 10) %>%
kable(format = 'latex', booktabs = TRUE,
caption = 'mycaption') %>%
# kableExtra::landscape() %>%
kable_styling(latex_options = c('hold_position', 'scale_down'))
```
---
title: "Untitled"
output: powerpoint_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Table
```{r table, echo=FALSE, message=FALSE, warning=FALSE}
library(tidyverse)
library(kableExtra)
mtcars %>%
count(cyl) %>%
ungroup() # %>%
# kable() %>%
# kable_styling()
```
I'm working off the repro above. I'd like to present the mtcars calculated data frame in a kable or kableExtra fashion, like this:
Instead the table outputs in the following console format:
## # A tibble: 3 x 2
## cyl n
## <dbl> <int>
## 1 4 11
## 2 6 7
## 3 8 14
How do I make my R PowerPoint tables pretty, and even better, editable in PowerPoint?
You can use flextable package. It's support powerpoint_presentation output with R Markdown. You will find below an example :
---
title: "Untitled"
output: powerpoint_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Table
```{r table, echo=FALSE, message=FALSE, warning=FALSE}
library(magrittr)
library(flextable)
mtcars[1:5,1:4] %>%
tibble::rownames_to_column() %>%
flextable() %>%
set_header_labels(rowname = "") %>%
add_header_row(values = c("", "Group 1", "Group 2"),
colwidths = c(1, 2, 2)) %>%
theme_zebra() %>% autofit()
```