I am trying to print a table by using following code in code chunk (Rmarkdown):
{r th_table, echo = FALSE, , warning = FALSE}
kbl(th_df, caption = "analysis", align = 'c',
booktabs = T) %>% kable_styling(latex_options = c("striped", "hold_position"), font_size = 8, full_width = T, position = "center") %>% row_spec(0, bold = T) %>% footnote(symbol = "Total handling time is in seconds")
When I am running this code it prints an output to my pdf document but the table is not striped. As soon as I remove full_width= T option from above code it display the table in striped formatting. Also if I add background="#FFB266" in row_spec(), table is printed without striped
How can I make full width striped table with background color to header or table?
Thanks for any help or suggestion.
Related
I am writing up an Rmarkdown document and am using this method to output two frames side by side. My caption appears at the bottom and I cannot figure out how to get it to appear at the top.
knitr::kables(
list(
df1[,c(1,3)] %>%
kbl(caption = 'Caption 1',booktabs=T,col.names = c('Col1','col2'),row.names = T) %>%
kable_styling(latex_options = c("striped", "hold_position")),
df2[,c(1,3)] %>%
kbl(caption = 'Caption 2',booktabs=T,col.names = c('Col1','col2')) %>%
kable_styling(latex_options = c("striped", "hold_position"))
)
)
The caption appears at the top when running the chunk in the rmarkdown document but upon knitting - returns captions 1 and 2 at the bottom of each side by side frame.
I'm trying to add footnote under my table but foot note is not getting displayed.
kbl(dataf,format="latex",longtable = T) %>%
kable_styling(latex_options = c("hold_position","repeat_header"),bootstrap_options = "bordered",full_width = F)%>%
row_spec(0, bold = T)%>%
add_footnote("klvnkkkkkkkkkkkkkkkkkkkkkkkkkkkkk",notation="number")%>%pack_rows("Group 1", 4, 5)
I am trying to generate a table using kableExtra on the toy iris data. I am able to successfully generate my output in PDF but I get some white spaces after the 5th row.
set.seed(123)
library(dplyr)
library(kableExtra)
df<- slice_sample(iris, n = 10)
kbl(df, caption = "Iris dataset", booktabs = T) %>%
kable_styling(latex_options = c("striped", "hold_position"))
I couldn't find any trim flags or so that I can pass them to the slice_sample. Not sure why it persists or is it by design?
The line spacing is a result of selecting booktabs = TRUE in the call to kbl which by definition includes '\addlinespace' in the default linesep argument every fifth row to make it easier to scan tables.
You can override this by setting linesep = "". Or for that matter introduce spacing in any order you like.
kbl(df, caption = "Iris dataset", booktabs = TRUE, linesep = "" ) %>%
kable_styling(latex_options = c("striped", "hold_position"))
In all my tables that I'm trying to produces in ioslides I am getting a result that shows a massive column name. How do I shrink this to make the table look okay?
Here is one example, but the same thing happens with every table. What am I missing? Ideally I'd want the content in the table to be the same font size.
Markdown:
## Test
``````{r, Test,echo=FALSE}
options("kableExtra.html.bsTable" = T)
kable(df, format= "html") %>%
kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed"), font_size = 12.5)
Image of my output:
You can change row sizes by using row_spec()
Since the header is interpreted as the row 0 you can change your header independently to fit your needings.
Try
kable(df, format= "html") %>%
kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed"), font_size = 12.5) %>%
row_spec(0, font_size=9)
for more settings check row_spec
I am currently working on a Markdown file (with latex) where I use kable() and kableExtra for my tables. The problem is that some of my tables are to big and doesn't fit on a pdf page (even in landscape).
I have tried to use latex_options = "scale_down" from kableExtra but for some reasons it doesn't work, it doesn't change anything. Here is an example of the code I'm running :
kable(dt, "latex", longtable = T, caption = "SampleCaption") %>%
add_header_above(c("","Mens" = 3, "Womens" = 3)) %>%
kable_styling(latex_options = c("striped", "scale_down", "repeat_header"),repeat_header_text = "",
full_width = F) %>%
column_spec(1, width = "10cm")
I already looked on Google and stackoverflow. Anyone have an idea of what I'm doing wrong? Thanks
Edit, here is the working code as requested in comments :
kable(dt, "latex", longtable = T, caption = "SampleCaption") %>%
add_header_above(c("","Mens" = 3, "Womens" = 3, "Total" = 2)) %>%
kable_styling(font_size = 7, latex_options = c("striped", "repeat_header"),repeat_header_text = "",
full_width = F) %>%
column_spec(1, width = "5cm")
This is not an answer but more like a clarification that since scale_down is using the resizebox in package graphicx while longtable is longtable and these two latex packages won't talk with each other, scale_down only works for normal tables.
In fact, you should be seeing a note in your console that "scale_down" doesn't work with longtable
Source in kableExtra
if (table_info$tabular == "longtable") {
warning("Longtable cannot be resized.")
return(x)
}