如何在R的Quarto中定义和使用新的“环境”?

huangapple go评论126阅读模式
英文:

How can I define and use a new "environment" in Quarto in R?

问题

我正在使用Quarto在RStudio中准备一份文档。输出将是一个LaTeX/PDF文档,文档类别是scrbook。在这本书中,我想每章都以“学习目标”开始。期望的输出如下所示:

  1. ----(在LaTeX中为“hrulefill”)
  2. 学习目标(以粗体字写)
  3. 在本章中,您将学到
  4. - 主题1
  5. - 主题2
  6. - 主题3
  7. ----(在LaTeX中为“hrulefill”)

我想保持这个“学习目标”部分的格式,就像LaTeX类别scrreprt中的“摘要”环境一样(即,左边和右边的间距更大,并且文本的字体不同)。问题是scrbook文档类别中没有定义“摘要”。

我的_quarto.yml文件如下所示:

  1. project:
  2. type: book
  3. book:
  4. title: “我的书名”
  5. author: Eva
  6. date: today
  7. date-format: DD/MM/YYYY
  8. #cover-image: cover.jpeg
  9. chapters:
  10. - index.qmd
  11. - part: Basics.qmd
  12. chapters:
  13. - chapter_one.qmd
  14. - chapter_two.qmd
  15. - chapter_three.qmd
  16. - part: Intermediate.qmd
  17. chapters:
  18. - chapter_four.qmd
  19. - chapter_five.qmd
  20. - Conclusion.qmd
  21. - part: Appendix.qmd
  22. chapters:
  23. - Packages.qmd
  24. - Datasets.qmd
  25. - Code_Snippets.qmd
  26. #bibliography: references.bib
  27. format:
  28. html:
  29. theme: cosmo
  30. pdf:
  31. documentclass: scrbook
  32. colorlinks: true
  33. toc: true
  34. toc-title: “目录”
  35. lot: true
  36. lof: true
  37. number-sections: true
  38. fig-cap-location: bottom
  39. tbl-cap-location: top
  40. code-line-numbers: true
  41. keep-tex: true
  42. author-meta: Eva
  43. title-meta: “我的书名”
  44. hyperrefoptions:
  45. - linktoc=all
  46. - pdfwindowui
  47. - pdfpagemode=FullScreen
  48. execute:
  49. echo: true
  50. warning: false
  51. message: false
  52. error: false
  53. cache: true
  54. editor: visual

所以,我有两个问题:

(1) 我如何自定义这样的环境?

(2) 我应该把这段代码放在Quarto的哪里?

英文:

I am preparing a document using Quarto in RStudio. The output will be a LaTeX/PDF document, with the document class scrbook. In this book, I want to start each chapter with "Learning Objectives". The desired output will look like this:

  1. ----("hrulefill" in LaTeX)
  2. Learning Objectives (Written in Bold Font)
  3. In this chapter, you will learn
  4. - Topic 1
  5. - Topic 2
  6. - Topic 3
  7. ---- ("hrulefill" in LaTeX)

I want to keep the formatting of this "Learning Objectives" part like the "abstract" environment in LaTeX class scrreprt (i.e., more space in Left Margin and Right Margin, and a different font for the text). The issue is that "abstract" is not defined for scrbook document class.

My _quarto.yml file looks like the following:

  1. project:
  2. type: book
  3. book:
  4. title: "My Book Title"
  5. author: "Eva"
  6. date: today
  7. date-format: DD/MM/YYYY
  8. #cover-image: cover.jpeg
  9. chapters:
  10. - index.qmd
  11. - part: Basics.qmd
  12. chapters:
  13. - chapter_one.qmd
  14. - chapter_two.qmd
  15. - chapter_three.qmd
  16. - part: Intermediate.qmd
  17. chapters:
  18. - chapter_four.qmd
  19. - chapter_five.qmd
  20. - Conclusion.qmd
  21. - part: Appendix.qmd
  22. chapters:
  23. - Packages.qmd
  24. - Datasets.qmd
  25. - Code_Snippets.qmd
  26. #bibliography: references.bib
  27. format:
  28. html:
  29. theme: cosmo
  30. pdf:
  31. documentclass: scrbook
  32. colorlinks: true
  33. toc: true
  34. toc-title: "Contents"
  35. lot: true
  36. lof: true
  37. number-sections: true
  38. fig-cap-location: bottom
  39. tbl-cap-location: top
  40. code-line-numbers: true
  41. keep-tex: true
  42. author-meta: "Eva"
  43. title-meta: "My Book Title"
  44. hyperrefoptions:
  45. - linktoc=all
  46. - pdfwindowui
  47. - pdfpagemode=FullScreen
  48. execute:
  49. echo: true
  50. warning: false
  51. message: false
  52. error: false
  53. cache: true
  54. editor: visual

So, I have two questions here:

(1) How can I define such environment myself?

(2) Where should I put this code in Quarto?

答案1

得分: 2

这篇帖子中,你可能可以根据你的喜好进行修改:

  1. format:
  2. pdf:
  3. documentclass: scrbook
  4. include-in-header:
  5. - text: |
  6. \providecommand{\abstractname}{学习目标} % 不在scrbook类中
  7. \newenvironment{secabstract}[1]{%
  8. \hrule
  9. \small\textbf{\abstractname:}
  10. \newline
  11. \vspace{0.1cm}
  12. %\small\emph #1 % emph接受一个参数
  13. \small\emph{#1} % \small\textit{#1}
  14. \itshape % 如果你想要文本斜体
  15. }{%
  16. \newline\hrule
  17. \vspace{0.6cm}
  18. }
  19. chapter_one.qmd:
  20. # 介绍
  21. \begin{secabstract}{在这一章中,您将学到}
  22. 主题1
  23. 主题2
  24. 主题3
  25. \end{secabstract}

输出

如何在R的Quarto中定义和使用新的“环境”?

英文:

From this post, you might be able to modify it to your liking:

  1. format:
  2. pdf:
  3. documentclass: scrbook
  4. include-in-header:
  5. - text: |
  6. \providecommand{\abstractname}{Learning Objectives} % not in scrbook class
  7. \newenvironment{secabstract}[1]{%
  8. \hrule
  9. \small\textbf{\abstractname: }
  10. \newline
  11. \vspace{0.1cm}
  12. %\small\emph #1 % emph takes an argument
  13. \small\emph{#1} % or \small\textit{#1}
  14. \itshape % use this if you want the text to be in italics
  15. }{%
  16. \newline\hrule
  17. \vspace{0.6cm}
  18. }

chapter_one.qmd:

  1. # Introduction
  2. \begin{secabstract}{In this chapter, you will learn}
  3. Topic 1
  4. Topic 2
  5. Topic 3
  6. \end{secabstract}

Output:

如何在R的Quarto中定义和使用新的“环境”?

huangapple
  • 本文由 发表于 2023年6月12日 09:25:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76453171.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定