[英]RStudio rticles knit to pdf book fails when cross-referencing equations
[英]Cross-referencing in rticles
bookdown 为方程、图形、表格和部分提供了很好的交叉引用选项: https ://bookdown.org/yihui/bookdown/cross-references.html
但是,当我将其设置为输出“文章:: elsevier_article”时,它们似乎不起作用。
文章中的交叉引用有哪些可用选项?
我没试过,但这里有一个可能的解决方案: https : //bookdown.org/yihui/bookdown/a-single-document.html
特别是,在您的 YAML 元数据中指定:
output:
bookdown::pdf_book:
base_format: rticles::elsevier_article
由于我是使用R Markdown
新手,因此我决定发布此答案,因为有些人可能会犯同样的错误。 我已经尝试过F Rodriguez-Sanchez 的回答,但没有奏效。 我收到以下消息:
! LaTeX Error: File `elsarticle.cls' not found.
! Emergency stop.
<read *>
Erro: Failed to compile report.tex. See report.log for more info.
它不起作用,因为我犯了一个新手错误,因为我试图添加建议的答案,选择New Markdown
然后选择Document
。
然后我尝试打开一个New R Markdown
,从rticles
包中选择From Template
和Elsevier Journal Article
。 在那之后,我使用了F Rodriguez-Sanchez建议的答案并且它起作用了!
最终的 yaml 标头是:
---
title: Short Paper
author:
- name: Alice Anonymous
email: alice@example.com
affiliation: Some Institute of Technology
footnote: Corresponding Author
- name: Bob Security
email: bob@example.com
affiliation: Another University
address:
- code: Some Institute of Technology
address: Department, Street, City, State, Zip
- code: Another University
address: Department, Street, City, State, Zip
abstract: |
This is the abstract.
It consists of two paragraphs.
journal: "An awesome journal"
date: "`r Sys.Date()`"
bibliography: mybibfile.bib
output:
bookdown::pdf_book:
base_format: rticles::elsevier_article
---
@maycca 请确保通过从模板中选择新文件并选择 Elsevier 期刊版本/模板来打开 RMarkdown。 模板将在文章安装后可用。
这将设置文章“基础设施”(特别是相应的 cls 和其他文件)。 这还包括一个 mybibfile.bib 示例(因此,我不需要注释 biblio)。 如果您选择将其保存在子文件夹中,请确保您的 Rmd 文件保存在该子文件夹中。
如上/下所示,更改 YAML 的output:
标签以包含 bookdown 和 baseformat rticles::elsevier_article 指针。
仔细检查冒号和制表符的使用。
根据上面的示例,您可以使用 bookdown 交叉引用,如下所示。 我用了
(i) 使用(ref:awesomeplotcaption)
在代码块之前定义的外部(bookdown)图形标题。 这对于保持块选项简短(er)很有用。
(ii) 对图\\@ref(fig:awesomeplot)
的(bookdown)交叉引用。 请注意\\@ref(fig:...)
使用块名称来使指针工作。 因此,请确保您的块名称带有标准字母、数字和破折号,即没有下划线!
按下针织按钮会变魔术!
---
title: Short Paper
author:
- name: Alice Anonymous
email: alice@example.com
affiliation: Some Institute of Technology
footnote: Corresponding Author
- name: Bob Security
email: bob@example.com
affiliation: Another University
address:
- code: Some Institute of Technology
address: Department, Street, City, State, Zip
- code: Another University
address: Department, Street, City, State, Zip
abstract: |
This is the abstract.
It consists of two paragraphs.
journal: "An awesome journal"
date: "`r Sys.Date()`"
#bibliography: mybibfile.bib
output:
bookdown::pdf_book:
base_format: rticles::elsevier_article
---
# First Heading
Some cool introductory text.
And an even more fascinating plot.
(ref:awesomeplotcaption) A simple demo plot
```{r awesomeplot, fig.cap="(ref:awesomeplotcaption)"}
x <- -5:5
y <- x^2
plot(x,y)
```
More explanatory text.
Using bookdown cross-referencing, have again a closer look at Fig. \@ref(fig:awesomeplot).
这导致以下结果:
PS 关注交叉引用并忽略代码块,这可以用echo = FALSE
隐藏。 下图如下(在本例中,通过 LATEX 放置)。 我截断了它以保持数字易于管理:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.