mitchelloharawild / vitae

R Markdown Résumés and CVs

Home Page:https://pkg.mitchelloharawild.com/vitae/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

yuans-cellbio opened this issue · comments

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?

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.