英文:
How can I define and use a new "environment" in Quarto in R?
问题
我正在使用Quarto在RStudio中准备一份文档。输出将是一个LaTeX/PDF文档,文档类别是scrbook。在这本书中,我想每章都以“学习目标”开始。期望的输出如下所示:
----(在LaTeX中为“hrulefill”)
学习目标(以粗体字写)
在本章中,您将学到
- 主题1
- 主题2
- 主题3
----(在LaTeX中为“hrulefill”)
我想保持这个“学习目标”部分的格式,就像LaTeX类别scrreprt中的“摘要”环境一样(即,左边和右边的间距更大,并且文本的字体不同)。问题是scrbook文档类别中没有定义“摘要”。
我的_quarto.yml文件如下所示:
project:
type: book
book:
title: “我的书名”
author: “Eva”
date: today
date-format: DD/MM/YYYY
#cover-image: cover.jpeg
chapters:
- index.qmd
- part: Basics.qmd
chapters:
- chapter_one.qmd
- chapter_two.qmd
- chapter_three.qmd
- part: Intermediate.qmd
chapters:
- chapter_four.qmd
- chapter_five.qmd
- Conclusion.qmd
- part: Appendix.qmd
chapters:
- Packages.qmd
- Datasets.qmd
- Code_Snippets.qmd
#bibliography: references.bib
format:
html:
theme: cosmo
pdf:
documentclass: scrbook
colorlinks: true
toc: true
toc-title: “目录”
lot: true
lof: true
number-sections: true
fig-cap-location: bottom
tbl-cap-location: top
code-line-numbers: true
keep-tex: true
author-meta: “Eva”
title-meta: “我的书名”
hyperrefoptions:
- linktoc=all
- pdfwindowui
- pdfpagemode=FullScreen
execute:
echo: true
warning: false
message: false
error: false
cache: true
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:
----("hrulefill" in LaTeX)
Learning Objectives (Written in Bold Font)
In this chapter, you will learn
- Topic 1
- Topic 2
- Topic 3
---- ("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:
project:
type: book
book:
title: "My Book Title"
author: "Eva"
date: today
date-format: DD/MM/YYYY
#cover-image: cover.jpeg
chapters:
- index.qmd
- part: Basics.qmd
chapters:
- chapter_one.qmd
- chapter_two.qmd
- chapter_three.qmd
- part: Intermediate.qmd
chapters:
- chapter_four.qmd
- chapter_five.qmd
- Conclusion.qmd
- part: Appendix.qmd
chapters:
- Packages.qmd
- Datasets.qmd
- Code_Snippets.qmd
#bibliography: references.bib
format:
html:
theme: cosmo
pdf:
documentclass: scrbook
colorlinks: true
toc: true
toc-title: "Contents"
lot: true
lof: true
number-sections: true
fig-cap-location: bottom
tbl-cap-location: top
code-line-numbers: true
keep-tex: true
author-meta: "Eva"
title-meta: "My Book Title"
hyperrefoptions:
- linktoc=all
- pdfwindowui
- pdfpagemode=FullScreen
execute:
echo: true
warning: false
message: false
error: false
cache: true
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
从这篇帖子中,你可能可以根据你的喜好进行修改:
format:
pdf:
documentclass: scrbook
include-in-header:
- text: |
\providecommand{\abstractname}{学习目标} % 不在scrbook类中
\newenvironment{secabstract}[1]{%
\hrule
\small\textbf{\abstractname:}
\newline
\vspace{0.1cm}
%\small\emph #1 % emph接受一个参数
\small\emph{#1} % 或 \small\textit{#1}
\itshape % 如果你想要文本斜体
}{%
\newline\hrule
\vspace{0.6cm}
}
chapter_one.qmd:
# 介绍
\begin{secabstract}{在这一章中,您将学到}
主题1
主题2
主题3
\end{secabstract}
输出:
英文:
From this post, you might be able to modify it to your liking:
format:
pdf:
documentclass: scrbook
include-in-header:
- text: |
\providecommand{\abstractname}{Learning Objectives} % not in scrbook class
\newenvironment{secabstract}[1]{%
\hrule
\small\textbf{\abstractname: }
\newline
\vspace{0.1cm}
%\small\emph #1 % emph takes an argument
\small\emph{#1} % or \small\textit{#1}
\itshape % use this if you want the text to be in italics
}{%
\newline\hrule
\vspace{0.6cm}
}
chapter_one.qmd:
# Introduction
\begin{secabstract}{In this chapter, you will learn}
Topic 1
Topic 2
Topic 3
\end{secabstract}
Output:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论