-
-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using kable_style with position on a table with a caption #221
Comments
Hmm, it looks like |
I just wanted to add to this. The
But I do get an error if I add
|
Using the OP's original example as an example.
gives you
which won't work. However, if you move
This is more like a behavior for What I can do here is to add an extra step to move that caption line to the bottom if that exists. I'm not very sure because 1. I'm not sure if this is the only solution 2. I prefer to keep caption on top... If any latex savvy people are reading this thread, please let me know if you have a good solution. Thanks |
Thank you for your quick responses, that would be great as I really need this for layouting my thesis! Unfortunately I am a bloody beginner on latex. |
@soerensen3 well, if you just need a quick and easy solution, good news is that you can use kableExtra with xtable which does put table caption at bottom... You just have to let kableExtra think you are feeding it a kable....😛
|
Thank you! This works perfectly! So in case this doesn't get fixed in time I will use this! |
Yeah, if it's getting too "risky" to move that caption by kableExtra, this might be the permanent solution. I will make some changes to that |
Hello @haozhu233 - This work around worked well for me for placing the table and giving it a header but I am unable to use the pack_rows() function with it. For example I tried: xtable(cars[1:5,1:2], caption = "Test") %>% That seemed to have no effect on the table. Is there any update on this issue? Or is there a way to add this to the work around? I tried to find a way to group rows in xtable() and was unsuccessful. Thank you! |
Has there been any update to this issue, preferably without moving the caption below the table? I am getting the same errors as OP whenever I set the table position = "float_left" or "float_right." |
I also had this issue while knitting to pdf, and created this extremely hacky workaround. The goal was merely to be able to use pack_rows with position="float_left/right", I didn't resolve the issue of moving the caption to the top unfortunately. Here is the code: library(stringr)
fix_wrap_kable <- function(kbl) {
kbl <- kbl %>%
str_remove(paste0("\\\\caption[{].+[}]\\n")) %>% # Removes the first caption
str_replace("\\\\end[{]tabular[}]",
paste0("\\\\end{tabular}\n\\\\caption{",attributes(kbl)$kable_meta$caption %>% # Adds the new caption using the string supplied in the kable 'caption' argument.
# The '{0,100}' is just a hack around lookbehind needing a set length, so the function will not work if the table label is longer
str_replace("(?<=[(]\\\\#.{0,100})[)]","}") %>% # Fixes and issue with pandoc syntax being mixed with LaTeX
str_replace("\\label[{]|[(]\\\\#","\\\\\\\\label{"),"}\n")) %>% # Adds an appropriate amount of backslashes before "\label"
set_attributes(attributes(kbl)) # Ensures that the returned object is still a kable
attributes(kbl)$kable_meta$caption <- NA # Removes the caption from the metadata
return(kbl)
} basically it just removes the caption before the table and inserts it again afterwards. It should also work with bookdown::pdf_document2. For convenience the function is made to be used with the pipe system in accordance with the other functions in kableExtra/knitr. Usage:
Hopefully it is of use to someone, and at least it shows that it is possible to have a caption, while wrapping text around the kable and using grouped rows. |
The attached code produces a latex error for me when knitting to pdf:
r markdown code example
kable_styling( kable( cars, booktabs=T, caption="cars"), position = "float_right" )
The error disappears if I remove the kable_style part or the caption.
I'm using the cran tinytex package (v.0.5).
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 3
minor 5.0
year 2018
month 04
day 23
svn rev 74626
language R
version.string R version 3.5.0 (2018-04-23)
nickname Joy in Playing
The text was updated successfully, but these errors were encountered: