Skip to content
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

allow caption in Rmd #72

Closed
davidgohel opened this issue Jun 26, 2018 · 7 comments
Closed

allow caption in Rmd #72

davidgohel opened this issue Jun 26, 2018 · 7 comments

Comments

@davidgohel
Copy link
Owner

Find a solution to add caption to flextable/regulartable

@jancrichter
Copy link

jancrichter commented Aug 30, 2018

I use the very nice packag captioner for this purpose, by simply using it to add a aption in an additional header row. It actually works so well and simple that I do not think an additional mechanism is needed for this.

Should you be interested to hear it, I can gladly elaborate on how exactly I use the package.

Cheers
Jan

@davidgohel
Copy link
Owner Author

Dear Jan,

Just to let you know, the subject is not dead but I am not able to work on it for the moment. I will later :)

David

@ahmadzai
Copy link

I use the very nice packag captioner for this purpose, by simply using it to add a aption in an additional header row. It actually works so well and simple that I do not think an additional mechanism is needed for this.

Should you be interested to hear it, I can gladly elaborate on how exactly I use the package.

Cheers
Jan

Hi Jan,

Could you please let me know, how did you add caption to flextable using captioner.

Thanks in advance,
Wazir

@jancrichter
Copy link

Hi Wazir,

in Captioner you define a function, that creates a caption string according to your needs including the table number when you call it. https://cran.r-project.org/web/packages/captioner/vignettes/using_captioner.html

tab_nums <- captioner::captioner(prefix = "Tab.\\ ", auto_space = FALSE, levels = 2)

When calling the captioner function, you give the table a unique identifer so later you can call your captioner function again, giving that name, to cite the respective table, with the correct number.

What I simply did, is to write this caption string into the header of a flextable. Works a charm.

library(dplyr)

 caption <- tab_nums(name = 'table_name', caption = 'This is a table.')

 t <- flextable(df)

 header.df <- data.frame(col_keys = t$col_keys,
                                          caption = rep(caption, (ncol(df)),
                             stringsAsFactors = FALSE)
 
 
 
 t  <- t %>%  set_header_df(mapping = header.df) %>% merge_at(i=1, part='header')

Cannot test the code right now. But something like this should work.

Cheers, Jan

@dmenne
Copy link

dmenne commented Dec 17, 2018

@davidgohel
Copy link
Owner Author

There is now a set_caption() function but it will only have an effect when output is HTML.

For PowerPoint output, there is no such concept available.

For Word output, you can add captions but not in the table - a Word document is expecting the caption to be a paragraph located not in the table but just before or after the table.

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants