😎 Give your xaringan slides some style
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

132 lines
4.1KB

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