😎 Give your xaringan slides some style
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

104 lines
3.5KB

  1. <!-- Need to set [adding-custom-css] -->
  2. [google-fonts]: https://fonts.google.com
  3. ### Default Fonts
  4. **xaringanthemer** by default uses a different set of default fonts for heading and body fonts.
  5. The new defaults use
  6. [Cabin](https://fonts.google.com/specimen/Cabin)
  7. for headings and
  8. [Noto Sans](https://fonts.google.com/specimen/Noto+Sans)
  9. for body text.
  10. These fonts are easier to read on screens and at a distance during presentations,
  11. and they support a wide variety of languages and weights.
  12. Another reason for the change is that the xaringan (remarkjs) default body font,
  13. _Droid Serif_,
  14. is no longer officially included in Google Fonts.
  15. If you would like to use the fonts from the
  16. [default xaringan theme](https://slides.yihui.name/xaringan/),
  17. you can use the following arguments in your style function.
  18. ```{r eval=FALSE, echo=TRUE}
  19. style_xaringan(
  20. text_font_family = "Droid Serif",
  21. text_font_url = "https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic",
  22. header_font_google = google_font("Yanone Kaffeesatz")
  23. )
  24. ```
  25. ### Custom and _Google Font_ Fonts
  26. **xaringanthemer** makes it easy to use
  27. [Google Fonts][google-fonts]
  28. in your presentations
  29. (provided you have an internet connection during the presentation)
  30. or to fully specify your font files.
  31. To use [Google Fonts][google-fonts],
  32. set the `<type>_font_google` theme arguments --
  33. ```{r results='asis', echo=FALSE}
  34. cat(paste0("`", tvv[grepl("_font_google$", tvv)], "`", collapse = ", "))
  35. ```
  36. --- using the `google_font()` helper.
  37. The help documentation in `?google_font` provides more info.
  38. ```{r eval=FALSE, echo=TRUE}
  39. style_mono_light(
  40. header_font_google = google_font("Josefin Slab", "600"),
  41. text_font_google = google_font("Work Sans", "300", "300i"),
  42. code_font_google = google_font("IBM Plex Mono")
  43. )
  44. ```
  45. If you set an `<type>_font_google` theme arguments,
  46. then `<type>_font_family`, `<type>_font_weight` and `<type>_font_url`
  47. are overwritten --
  48. where `<type>` is one of `header`, `text`, or `code`.
  49. To use a font hosted outside of Google fonts,
  50. you need to provide both `<type>_font_family` and `<type>_font_url`.
  51. For example,
  52. suppose you want to use a code font with ligatures for your code chunks,
  53. such as
  54. [Fira Code](https://github.com/tonsky/FiraCode),
  55. which would be declared with `code_font_family`.
  56. The
  57. [browser usage](https://github.com/tonsky/FiraCode#browser-support)
  58. section of the Fira Code README
  59. provides a CSS URL to be used with an `@import` statement
  60. that you can use with the `code_font_url` argument.
  61. ```{r eval=FALSE, echo=TRUE}
  62. style_solarized_dark(
  63. code_font_family = "Fira Code",
  64. code_font_url = "https://cdn.jsdelivr.net/gh/tonsky/FiraCode@2/distr/fira_code.css"
  65. )
  66. ```
  67. Remember that you need to supply either
  68. `<type>_google_font` using the `google_font()` helper
  69. _or both_ `<type>_font_family` and `<type>_font_url`.
  70. ### Using Additional Fonts
  71. If you want to use additional fonts for use in [custom CSS definitions][adding-custom-css],
  72. use the `extra_fonts` argument to pass a list of URLs or `google_font()`s.
  73. Notice that you will need to add custom CSS (for example, via `extra_css`)
  74. to use the fonts imported in `extra_fonts`.
  75. ```{r eval=FALSE, echo=TRUE}
  76. style_mono_light(
  77. extra_fonts = list(
  78. google_font("Sofia"),
  79. # Young Serif by uplaod.fr
  80. "https://cdn.jsdelivr.net/gh/uplaod/YoungSerif/fonts/webfonts/fontface.css",
  81. ),
  82. extra_css = list(
  83. ".title-slide h2" = list("font-family" = "Sofia"),
  84. blockquote = list("font-family" = "youngserifregular")
  85. )
  86. )
  87. ```