Cross-referencing in rticles
Asked Answered
S

3

6

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?

Snath answered 19/2, 2017 at 18:28 Comment(0)
M
6

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
Mealymouthed answered 21/2, 2017 at 11:33 Comment(2)
Thank you for response. I'm aware of this solution. However I wonder if rticles do not offers its own referencing system. Regarding your response, I have problem with base_format of pdf_book. If I add line 'citation_package: natbib' in output, bibliography is not compiling at all. But I guess this is for different question. Are you sure there are no 'native' referencing options for rticles?Snath
You could try captioner package. See vignette or this short tutorial. Or see also this related SO question: #38861541Mealymouthed
M
2

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: [email protected]
    affiliation: Some Institute of Technology
    footnote: Corresponding Author
  - name: Bob Security
    email: [email protected]
    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
---
Matronly answered 18/7, 2018 at 13:58 Comment(4)
I have the same problem. Can you please add to your answer and example about how do you cross reference the figure? suggestion of \@ref(my-chunk-name) does not work. Thank youAnatomize
@Anatomize ` c.f. Fig. \@ref(fig:my-chunk-name)` should get you there.Biotic
Thank you @Ray, I have tried it but it still does not work.. As output in RMarkdown, I am using output: bookdown::pdf_book: base_format: rticles::elsevier_article as suggested. Maybe there is another solution? Thanks againAnatomize
No worries @maycca. I paste a longer answer below. Hope this helps.Biotic
B
0

@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: [email protected]
    affiliation: Some Institute of Technology
    footnote: Corresponding Author
  - name: Bob Security
    email: [email protected]
    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 :)

Biotic answered 4/10, 2020 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.