4
votes

The bookdown offers great cross-referencing options for equations, figures, tables and sections: https://bookdown.org/yihui/bookdown/cross-references.html

However, they seems to not work when I set as an output 'rticles::elsevier_article'.

What are the available options for cross-referencing in rticles?

3

3 Answers

5
votes

I haven't tried, but there is a possible solution here: https://bookdown.org/yihui/bookdown/a-single-document.html

Particularly, specify in your YAML metadata:

output:
  bookdown::pdf_book:
    base_format: rticles::elsevier_article
2
votes

Since I am new using R Markdown I have decided to post this answer as some people may incur in the same mistake. I have tried myself F Rodriguez-Sanchez answer but it did not work. I got the following message:

! LaTeX Error: File `elsarticle.cls' not found.

! Emergency stop.
<read *> 

Erro: Failed to compile report.tex. See report.log for more info.

It did not work because I was making a rookie mistake since I was trying to add the suggested answer choosing New Markdownand then choosing Document.

I have then tried to open a New R Markdown choosing From Template and Elsevier Journal Article from rticles package. After that, I have used F Rodriguez-Sanchez suggested answer and it worked!

The final yaml header was:

---
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
---
0
votes

@maycca please make sure to open the RMarkdown by choosing New Files from Template and select the Elsevier Journal version/template. The template(s) will be available after the rticles installation.

This will setup the article "infrastructure" (in particular the respective cls and other files). This also includes a mybibfile.bib example (thus, I would have not needed to comment the biblio out). If you choose to save this in a sub-folder, make sure that your Rmd file is saved in that sub-folder.

As presented above/below change the output: tag of the YAML to include the bookdown and baseformat rticles::elsevier_article pointer.
Check the use of colons and tabs carefully.

Based on the example above, you can then use the bookdown cross-referencing as shown below. I used
(i) an external (bookdown) figure caption defined before the code chunk using (ref:awesomeplotcaption). This is useful to keep the chunk options short(er).
(ii) a (bookdown) cross-reference to the figure \@ref(fig:awesomeplot). Please note that the \@ref(fig:...) uses the chunk-name to make the pointer work. Thus, make sure your chunk-name comes with standard letters, numbers, and dashes, i.e. no underscore!

Hitting the knit button will do the magic!

---
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).

This results in the following:

bookdown-reference-in-elsevier-template

P.S. Focus on the cross-reference and ignore the code-chunk, this could be hidden with echo = FALSE. The figure follows below (in this example, placed via LATEX). I truncated it to keep the figure manageable :)