😎 Give your xaringan slides some style
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

135 lines
3.6KB

  1. ---
  2. title: "Xaringan CSS Theme Generator"
  3. output: rmarkdown::html_vignette
  4. vignette: >
  5. %\VignetteIndexEntry{Overview of xaringanthemer}
  6. %\VignetteEngine{knitr::rmarkdown}
  7. %\VignetteEncoding{UTF-8}
  8. ---
  9. ```{r setup, include = FALSE}
  10. knitr::opts_chunk$set(
  11. collapse = TRUE,
  12. results = "asis",
  13. echo = FALSE,
  14. comment = "#>",
  15. out.width = "100%"
  16. )
  17. library(xaringanthemer)
  18. ```
  19. ```{css echo=FALSE}
  20. img { max-width: 100%; }
  21. ```
  22. [xaringan]: https://github.com/yihui/xaringan
  23. [remarkjs]: https://github.com/gnab/remark
  24. Jump to:
  25. [Quick Intro](#quick-intro),
  26. [Themes](#themes),
  27. [Theme Settings](#theme-settings),
  28. [Fonts](#fonts),
  29. [Colors](#colors),
  30. [Adding Custom CSS](#adding-custom-css)
  31. ## Quick Intro
  32. [theme-functions]: #themes
  33. [theme-settings]: #theme-settings
  34. [template-variables]: template-variables.html
  35. ```{r child="../man/fragments/_quick-intro.Rmd"}
  36. ```
  37. ## Themes
  38. ```{r child="../man/fragments/_themes.Rmd"}
  39. ```
  40. ## Theme Settings
  41. The theme functions listed above are just wrappers around the central function of this package, `style_xaringan()`.
  42. If you want to start from the default **xaringan** theme and make a few modifications, start there.
  43. All of the theme template variables are repeated in each of the theme functions (instead of relying on `...`) so that you can use autocompletion to find and change the defaults for any theme function.
  44. To override the default value of any theme functions, set the appropriate argument in the theme function.
  45. A table of all template variables is included in [`vignette("template-variables", "xaringanthemer")`](template-variables.html).
  46. As an example, try loading `xaringanthemer`, type out `style_duo_theme(` and then press <kbd>Tab</kbd> to see all of the theme options.
  47. All of the theme options are named so that you first think of the element you want to change, then the property of that element.
  48. Here are some of the `text_` theme options:
  49. ```{r, results='asis', echo=FALSE}
  50. tvv <- xaringanthemer:::template_variables$variable
  51. cat(paste0("- `", tvv[grepl("^text_", tvv)][1:5], "`"), sep = "\n")
  52. cat("- *and more ...*")
  53. ```
  54. And here are the title slide theme options:
  55. ```{r results='asis', echo=FALSE}
  56. cat(paste0("- `", tvv[grepl("^title_slide_", tvv)], "`"), sep = "\n")
  57. ```
  58. ## Fonts
  59. [adding-custom-css]: #adding-custom-css
  60. ```{r child="../man/fragments/_fonts.Rmd"}
  61. ```
  62. ## Colors
  63. ```{r child="../man/fragments/_colors.Rmd"}
  64. ```
  65. ## Adding Custom CSS
  66. You can also add custom CSS classes using the `extra_css` argument in the theme functions.
  67. This argument takes a named list of CSS definitions each containing a named list of CSS property-value pairs.
  68. ```r
  69. extra_css <- list(
  70. ".small" = list("font-size" = "90%"),
  71. ".full-width" = list(
  72. display = "flex",
  73. width = "100%",
  74. flex = "1 1 auto"
  75. )
  76. )
  77. ```
  78. If you would rather keep your additional css definitions in a separate file, you can call `style_extra_css()` separately.
  79. Just be sure to include your new CSS file in the list of applied files in your YAML header.
  80. ```r
  81. style_extra_css(css = extra_css, outfile = "custom.css")
  82. ```
  83. ```{r results='asis', echo=FALSE}
  84. extra_css <- list(
  85. ".small" = list("font-size" = "90%"),
  86. ".full-width" = list(
  87. display = "flex",
  88. width = "100%",
  89. flex = "1 1 auto"
  90. )
  91. )
  92. cat(
  93. "\n```css",
  94. "/* Extra CSS */",
  95. xaringanthemer:::list2css(extra_css),
  96. "```",
  97. sep = "\n"
  98. )
  99. ```
  100. This is most helpful when wanting to define helper classes to work with the [remark.js][remarkjs] `.class[]` syntax.
  101. Using the above example, we could add slide text `.small[in smaller font size]`.
  102. ```{r child="../man/fragments/_thanks.Rmd"}
  103. ```