😎 Give your xaringan slides some style
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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