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

使用bookdown的R Markdown论文中,acknowledgements不显示如何解决?

解决bookdown中致谢内容不显示的问题

问题根源在于:bookdown::pdf_document2的默认模板仅支持abstract这类标准YAML字段的自动渲染,acknowledgements不属于默认会被处理的字段,所以即使在YAML中定义也不会显示。以下是三种可行的解决方法:

方法一:直接在主文档中插入致谢内容

无需依赖YAML字段,直接在主Rmd文件的合适位置(比如摘要之后、前言之前)添加致谢章节并读取外部文件内容:

---
geometry: "left=4cm, right=2.5cm, top=2.5cm, bottom=2.5cm"
title: |
  Line1\
  Line2\
  Line3
author: |
  abc_123
abstract: |
  `r paste(readLines("front-and-back-matter/_abstract.Rmd"), collapse = "\n  ")`
site: bookdown::bookdown_site
output:
  bookdown::pdf_document2:
    toc: no
---

# Acknowledgements

`r paste(readLines("front-and-back-matter/_acknowledgements.Rmd"), collapse = '\n')`

# Preface

Pref1...PrefN
Pref1...PrefN

Pref1...PrefN

方法二:自定义LaTeX模板支持acknowledgements字段

  1. 复制默认LaTeX模板到项目目录:
file.copy(system.file("rmarkdown/templates/pdf_document/resources/default.latex", package = "rmarkdown"), "template.tex")
  1. 编辑template.tex:

    • 在\usepackage区块后添加致谢环境定义:
      \newenvironment{acknowledgements}{%
        \section*{Acknowledgements}%
      }{%
        \par
      }
      
    • 找到abstract渲染的代码块,在其后添加致谢的渲染逻辑:
      $if(acknowledgements)$
      \begin{acknowledgements}
      $acknowledgements$
      \end{acknowledgements}
      $endif$
      
  2. 在YAML中指定自定义模板:

output:
  bookdown::pdf_document2:
    toc: no
    template: template.tex

此时原YAML中的acknowledgements字段内容就会被正常渲染。

方法三:利用bookdown的文件顺序自动渲染

创建独立的致谢文件(比如00-acknowledgements.Rmd),bookdown会按文件名排序自动编译该文件,内容如下:

# Acknowledgements

`r paste(readLines("front-and-back-matter/_acknowledgements.Rmd"), collapse = '\n')`

将该文件放在项目根目录,编译时致谢会自动出现在主文档内容之前。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 13:07:21