【问题标题】:Why figure numbers with two digits separated by dot are shown only in html_document2?为什么用点分隔的两位数字的数字仅显示在 html_document2 中?
【发布时间】:2018-01-14 21:15:48
【问题描述】:

这是一个简单的 RMarkdown 文档,包含两个部分和两个图像。

---
output:
  bookdown::html_document2: default
  bookdown::word_document2: default
  bookdown::pdf_document2: default
---

\newpage

# Part 1

Part 1 starts here. See Figure \@ref(fig:fig1-1) 

![(\#fig:fig1-1) expected to be Figure 1.1.](/usr/lib/rstudio/www/images/rstudio.png)

# Part 2

Part 2 starts here. See Figure \@ref(fig:fig2-1) 

![(\#fig:fig2-1) expected to be Figure 2.1.](/usr/lib/rstudio/www/images/rstudio.png)

我预计两个图像将使用 Knit 渲染为以下编号 - 第一个是 图 1.1,第二个是 图 2.1。但我只在html_document2 得到这个渲染(见下图):

我使用最新的 RStudio 1.1.414 和来自 Git (38efc82) 的最新预订。 我这里有两个问题:

  1. 为什么我在 Word 或 PDF 中没有图 1.1图 2.1
  2. 如何在 Word 或 PDF 中获取 图 1.1图 2.1

【问题讨论】:

    标签: r r-markdown bookdown


    【解决方案1】:

    我只能通过 LaTeX 处理 PDF 输出。默认情况下,使用 LaTeX 文档类article,它使用连续数字编号。如果您的文档太长以至于对每个顶级部分中的数字进行编号是有意义的,那么您可能希望使用 reportbook 代替,例如:

    ---
    documentclass: book
    output:
      bookdown::pdf_document2: default
      bookdown::word_document2: default
      bookdown::html_document2: default
    ---
    

    或者你可以使用一些 LaTeX 包来改变数字的格式,例如:

    ---
    header-includes:
      \usepackage{chngcntr}
      \counterwithin{figure}{section}
    output:
      bookdown::pdf_document2: default
      bookdown::word_document2: default
      bookdown::html_document2: default
    ---
    

    如果您仍然使用该软件包,另一种选择是来自amsmath\numberwithin 命令。

    【讨论】:

    • 谢谢!对于 PDF,它可以工作。我将尝试获取 Word 的解决方案(或在此处等待解决方案)。
    猜你喜欢
    • 2022-08-18
    • 2011-05-27
    • 2023-04-05
    • 1970-01-01
    • 2022-12-05
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2023-04-07
    相关资源
    最近更新 更多