作者:Yihui Xie
译者:郑宝童
日期:2021.05.19


2.6 Cross-references

We have explained how cross-references work for equations (Section 2.2.1), theorems (Section 2.2.2), figures (Section 2.4), and tables (Section 2.5). In fact, you can also reference sections using the same syntax \@ref(label), where label is the section ID. By default, Pandoc will generate an ID for all section headers, e.g., a section # Hello World will have an ID hello-world. We recommend you to manually assign an ID to a section header to make sure you do not forget to update the reference label after you change the section header. To assign an ID to a section header, simply add {#id} to the end of the section header. Further attributes of section headers can be set using standard Pandoc syntax.

我们已经解释了交叉引用是如何为等式(第 2.2.1节)、定理(第2.2.2节)、图(第2.4节)和表(第2.5节)工作的。事实上,您也可以使用相同的语法\@ref(label),来引用section,其中label是section ID。默认情况下,Pandoc将为所有的section头生成一个ID,例如,一个section # Hello World 将有一个ID Hello - World。我们建议您手动为一个节标头分配一个ID,以确保您在更改节标头后没有忘记更新引用标签。要给一个节头分配一个ID,只需添加{#id} 到节标题的结尾。section头的其他属性可以使用标准的Pandoc语法( Pandoc syntax)设置。

When a referenced label cannot be found, you will see two question marks like ??, as well as a warning message in the R console when rendering the book.

当无法找到引用的标签时,您将看到两个问号,如??,以及在呈现图书时在R控制台中显示的警告消息。

You can also create text-based links using explicit or automatic section IDs or even the actual section header text.

您还可以使用显式的或自动的节id甚至实际的节标题文本来创建基于文本的链接。

  • If you are happy with the section header as the link text, use it inside a single set of square brackets:
  • There are two ways to specify custom link text:

    • [link text][Section header text], e.g., “non-English books” via [non-English books][Internationalization]
    • [link text](#ID), e.g., “Table stuff” via [Table stuff](#tables)
  • 如果你对section头作为链接文本感到满意,就把它放在一组方括号中:

  • 下面是指定自定义链接文本的两种方法:

Cross-references still work even when we refer to an item that is not on the current page of the PDF or HTML output. For example, see Equation (2.1) and Figure 2.4.

Pandoc文档提供了关于自动节id和隐式头引用的更多细节。即使我们引用的条目不在PDF或HTML输出的当前页面上,交叉引用仍然可以工作。如 公式(2.1) and 图 2.4.