😎 Give your xaringan slides some style
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

140 lines
3.8KB

  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. ```{r toc, results='asis', echo=FALSE, message=FALSE, eval=FALSE}
  25. devtools::source_gist("c83e078bf8c81b035e32c3fc0cf04ee8", filename = 'render_toc.R')
  26. x <- render_toc("README.Rmd", toc_depth = 3)
  27. gsub(" -", "-", sub("^-.+?\n", "", x))
  28. ```
  29. Jump to:
  30. [Quick Intro](#quick-intro),
  31. [Themes](#themes),
  32. [Theme Settings](#theme-settings),
  33. [Adding Custom CSS](#adding-custom-css),
  34. [Fonts](#fonts)
  35. ## Quick Intro
  36. [theme-functions]: #themes
  37. [theme-settings]: #theme-settings
  38. [template-variables]: template-variables.html
  39. ```{r child="../man/fragments/_quick-intro.Rmd"}
  40. ```
  41. ## Themes
  42. ```{r child="../man/fragments/_themes.Rmd"}
  43. ```
  44. ## Theme Settings
  45. The theme functions listed above are just wrappers around the central function of this package, `style_xaringan()`.
  46. If you want to start from the default **xaringan** theme and make a few modifications, start there.
  47. 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.
  48. To override the default value of any theme functions, set the appropriate argument in the theme function.
  49. A table of all template variables is included in [`vignette("template-variables", "xaringanthemer")`](template-variables.html).
  50. As an example, try loading `xaringanthemer`, type out `style_duo_theme(` and then press <kbd>Tab</kbd> to see all of the theme options.
  51. 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.
  52. Here are some of the `text_` theme options:
  53. ```{r, results='asis', echo=FALSE}
  54. tvv <- xaringanthemer:::template_variables$variable
  55. cat(paste0("- `", tvv[grepl("^text_", tvv)][1:5], "`"), sep = "\n")
  56. cat("- *and more ...*")
  57. ```
  58. And here are the title slide theme options:
  59. ```{r results='asis', echo=FALSE}
  60. cat(paste0("- `", tvv[grepl("^title_slide_", tvv)], "`"), sep = "\n")
  61. ```
  62. ## Fonts
  63. [adding-custom-css]: #adding-custom-css
  64. ```{r child="../man/fragments/_fonts.Rmd"}
  65. ```
  66. ## Colors
  67. ```{r child="../man/fragments/_colors.Rmd"}
  68. ```
  69. ## Adding Custom CSS
  70. You can also add custom CSS classes using the `extra_css` argument in the theme functions.
  71. This argument takes a named list of CSS definitions each containing a named list of CSS property-value pairs.
  72. ```r
  73. extra_css <- list(
  74. ".small" = list("font-size" = "90%"),
  75. ".full-width" = list(
  76. display = "flex",
  77. width = "100%",
  78. flex = "1 1 auto"
  79. )
  80. )
  81. ```
  82. If you would rather keep your additional css definitions in a separate file, you can call `style_extra_css()` separately.
  83. Just be sure to include your new CSS file in the list of applied files in your YAML header.
  84. ```r
  85. style_extra_css(css = extra_css, outfile = "custom.css")
  86. ```
  87. ```{r results='asis', echo=FALSE}
  88. extra_css <- list(
  89. ".small" = list("font-size" = "90%"),
  90. ".full-width" = list(
  91. display = "flex",
  92. width = "100%",
  93. flex = "1 1 auto"
  94. )
  95. )
  96. cat(
  97. "\n```css",
  98. "/* Extra CSS */",
  99. xaringanthemer:::list2css(extra_css),
  100. "```",
  101. sep = "\n"
  102. )
  103. ```
  104. This is most helpful when wanting to define helper classes to work with the [remark.js][remarkjs] `.class[]` syntax.
  105. Using the above example, we could add slide text `.small[in smaller font size]`.
  106. ```{r child="../man/fragments/_thanks.Rmd"}
  107. ```