mitchelloharawild / vitae

R Markdown Résumés and CVs
https://pkg.mitchelloharawild.com/vitae/
1.23k stars 239 forks source link

Is it possible to use kable and kableExtra in awesome CV? #232

Closed yuans-cellbio closed 1 year ago

yuans-cellbio commented 1 year ago

I tried to insert a table into my CV. It works if I just use kable, but the style is not appealing. It also does not support all functions from kable.

For example, this works.

data.frame(
  "Journal" = LETTERS[1:5], 
  "Completed Review" = 1:5, 
  check.names = FALSE
) %>%
  kable(format = "latex", align = "c") %>%
  kable_classic(html_font = "sams-serif") %>%
  kable_styling(latex_options = c("hold_position"))

When I set longtable = TRUE, "LaTeX Error: Environment longtable undefined".

data.frame(
  "Journal" = LETTERS[1:5], 
  "Completed Review" = 1:5, 
  check.names = FALSE
) %>%
  kable(format = "latex", align = "c", longtable = TRUE) %>%
  kable_classic(html_font = "sams-serif") %>%
  kable_styling(latex_options = c("hold_position"))

If I add stripes, "! Undefined control sequence. \cellcolor".

data.frame(
  "Journal" = LETTERS[1:5], 
  "Completed Review" = 1:5, 
  check.names = FALSE
) %>%
  kable(format = "latex", align = "c") %>%
  kable_classic(html_font = "sams-serif") %>%
  kable_styling(latex_options = c("hold_position", "striped"))

Is there any way I can fix this?

yuans-cellbio commented 1 year ago

ChatGPT solved my problem... It blew my mind...

Here is its answer.

The issue with the longtable option is that it requires the longtable LaTeX package to be loaded. You can add the longtable package to the CV header using the header-includes option in the YAML header of your R Markdown file. Here is an example:

yaml

---
title: "My CV"
output:
  vitae::awesomecv:
    cvname: my_cv
header-includes:
  - \usepackage{longtable}
---

Regarding the \cellcolor issue, you can add the colortbl LaTeX package to the CV header using the same header-includes option. Here is an updated example:

yaml

---
title: "My CV"
output:
  vitae::awesomecv:
    cvname: my_cv
header-includes:
  - \usepackage{longtable}
  - \usepackage{colortbl}
---

Note that the striped option may not work well with the longtable package, so you may need to experiment with different options to achieve the desired style.