You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R的Quarto中自定义scrbook类PDF的Learning Objectives环境?

解决方案

(1) 自定义LaTeX环境

要实现类似scrreprt中abstract的格式,你可以直接用LaTeX命令定义一个新环境,模仿abstract的样式(加宽左右边距、调整字体),同时加上所需的上下水平线和标题。

完整的LaTeX定义代码如下:

% 定义Learning Objectives环境
\newenvironment{learningobjectives}{
  \par
  \vspace{1em}
  \hrulefill % 顶部水平线
  \vspace{0.5em}
  \begin{addmargin}[1.5cm]{1.5cm} % 加宽左右边距,数值可按需调整
    \textbf{\Large Learning Objectives}\\[0.5em] % 加粗大字体标题
    \begin{itshape} % 设置斜体字体,匹配scrreprt abstract的字体风格
}{
    \end{itshape}
  \end{addmargin}
  \vspace{0.5em}
  \hrulefill % 底部水平线
  \vspace{1em}
}

关键配置说明:

  • \addmargin[左边距]{右边距}:实现左右加宽的边距,可根据排版需求调整数值(比如改成1cm)
  • \textbf{\Large Learning Objectives}:设置加粗的大字体标题,对应你需要的样式
  • \begin{itshape}:将正文设置为斜体,匹配scrreprt中abstract环境的字体风格
  • \hrulefill生成上下水平线,\vspace控制各元素间的间距

(2) 代码放置位置

推荐两种方式,任选其一即可:

方式一:使用项目级LaTeX前置文件

  1. 在Quarto项目根目录新建preamble.tex文件,将上面的LaTeX定义代码粘贴进去。
  2. 修改_quarto.yml的PDF格式配置,添加include-in-header选项:
format:
  html:
    theme: cosmo
  pdf:
    documentclass: scrbook
    include-in-header: preamble.tex # 新增该行引用前置文件
    colorlinks: true
    # 其他原有配置保持不变...

方式二:直接写入index.qmd的YAML头部

如果不想单独创建preamble.tex,可以直接在index.qmd的开头YAML块中添加:

---
title: "My Book Title"
format:
  pdf:
    include-in-header:
      text: |
        \newenvironment{learningobjectives}{
          \par
          \vspace{1em}
          \hrulefill
          \vspace{0.5em}
          \begin{addmargin}[1.5cm]{1.5cm}
            \textbf{\Large Learning Objectives}\\[0.5em]
            \begin{itshape}
        }{
            \end{itshape}
          \end{addmargin}
          \vspace{0.5em}
          \hrulefill
          \vspace{1em}
        }
---

实际使用自定义环境

配置完成后,在每个章节的.qmd文件开头,用LaTeX环境语法插入内容即可:

\begin{learningobjectives}
In this chapter, you will learn
 - Topic 1
 - Topic 2
 - Topic 3
\end{learningobjectives}

内容的提问来源于stack exchange,提问作者Eva

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 11:02:54