I just started using kableExtra
library to make my tables look better in the PDF output.
But when I use kable()
function in R Notebook file, it does not show the output. Instead I see a large white space where the output should be.
Here is a screenshot:
When I Knit
the file to PDF I can see the output.
Here is a screenshot:
Is there a way I can make the output appear both in the Notebook and PDF?
Here is my code:
---
title: "R Notebook"
output:
pdf_document: default
html_notebook: default
---
```{r message=FALSE, warning=FALSE}
library(knitr)
library(kableExtra)
library(dplyr)
#plot(cars)
```
```{r}
cars %>%
slice(1:10) %>%
select(speed, dist) %>%
kable(format = "latex", booktabs = T) %>%
column_spec(column = 1:2, width = "0.5in")
```
The kable() function in knitr is a very simple table generator, and is simple by design. It only generates tables for strictly rectangular data such as matrices and data frames. You cannot heavily format the table cells or merge cells.
The kableExtra package (Zhu 2021) is designed to extend the basic functionality of tables produced using knitr::kable() (see Section 10.1).
Upon installing, inserttable registers a new RStudio Addin (Insert Table) that can be used to easily insert a table in a Rmd document. To use it, open a Rmd or R document and select “Addins –> Insert Table”.
latex - R - kable() used in .Rmd does not show output in notebook - Stack Overflow I just started using kableExtra library to make my tables look better in the PDF output. But when I use kable() function in R Notebook file, it does not show the output. Instead I see a large white... Stack Overflow About Products For Teams
1 Suppressing lengthy kable tables in Rmd inline output while retaining in final PDF 2 kableExtra: Vertical alignment not working in PDF output with many columns 2 Math symbols not rendered correctly in R notebook format from KableExtra table objects 2
For R Markdown documents, kable () uses the pipe format for tables by default, which looks like this: You can also generate simple tables, or tables in HTML, LaTeX, and reStructuredText: Please note that only the formats pipe and simple are portable, i.e., they work for any output document format.
For R Markdown documents, kable () uses the pipe format for tables by default, which looks like this: knitr::kable(head(mtcars 1:4]), "pipe")
You have to set a different kable format
parameter for each output and specify results = 'asis'
in chunk options.
For HTML / Notebook:
```{r, results='asis'}
cars %>%
slice(1:10) %>%
select(speed, dist) %>%
kable(format = "html", booktabs = T) %>%
column_spec(column = 1:2, width = "0.5in")
```
For PDF:
```{r, results='asis'}
cars %>%
slice(1:10) %>%
select(speed, dist) %>%
kable(format = "latex", booktabs = T) %>%
column_spec(column = 1:2, width = "0.5in")
```
I was having a similar problem, but it turns out that my editor theme's white default text was making the font in the .Rmd output invisible (but I could still highlight it).
My kable output was not working inside the .Rmd file--but was working fine when running the code in the console, and also when I knit the file. I was using the Idle Fingers editor theme (sort of a 'dark mode') and changing this to another theme fixed the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With