cite figure in other figure caption in markdown to pdf
Using R markdown with PDF output, I want to cite a figure into another figure caption. I also want to cite a BibTex reference in the caption. Any ideas? Here's an example of code:
---
title: "Untitled"
author: "me"
date: "today"
output:
pdf_document:
latex_engine: lualatex
number_sections: no
linestretch: 1.5
bibliography: input/Library.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
```{r}
df <- mtcars
library(ggplot2)
```
```{r, fig.cap="some stuff"}
ggplot(df, aes(cyl, mpg)) + geom_point()
```
```{r, fig.cap="some more stuff. here I'd like to cite figure 1. I would also like a BibTex citation"}
ggplot(df, aes(cyl, hp)) + geom_point()
```
r latex r-markdown pandoc
add a comment |
Using R markdown with PDF output, I want to cite a figure into another figure caption. I also want to cite a BibTex reference in the caption. Any ideas? Here's an example of code:
---
title: "Untitled"
author: "me"
date: "today"
output:
pdf_document:
latex_engine: lualatex
number_sections: no
linestretch: 1.5
bibliography: input/Library.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
```{r}
df <- mtcars
library(ggplot2)
```
```{r, fig.cap="some stuff"}
ggplot(df, aes(cyl, mpg)) + geom_point()
```
```{r, fig.cap="some more stuff. here I'd like to cite figure 1. I would also like a BibTex citation"}
ggplot(df, aes(cyl, hp)) + geom_point()
```
r latex r-markdown pandoc
add a comment |
Using R markdown with PDF output, I want to cite a figure into another figure caption. I also want to cite a BibTex reference in the caption. Any ideas? Here's an example of code:
---
title: "Untitled"
author: "me"
date: "today"
output:
pdf_document:
latex_engine: lualatex
number_sections: no
linestretch: 1.5
bibliography: input/Library.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
```{r}
df <- mtcars
library(ggplot2)
```
```{r, fig.cap="some stuff"}
ggplot(df, aes(cyl, mpg)) + geom_point()
```
```{r, fig.cap="some more stuff. here I'd like to cite figure 1. I would also like a BibTex citation"}
ggplot(df, aes(cyl, hp)) + geom_point()
```
r latex r-markdown pandoc
Using R markdown with PDF output, I want to cite a figure into another figure caption. I also want to cite a BibTex reference in the caption. Any ideas? Here's an example of code:
---
title: "Untitled"
author: "me"
date: "today"
output:
pdf_document:
latex_engine: lualatex
number_sections: no
linestretch: 1.5
bibliography: input/Library.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
```{r}
df <- mtcars
library(ggplot2)
```
```{r, fig.cap="some stuff"}
ggplot(df, aes(cyl, mpg)) + geom_point()
```
```{r, fig.cap="some more stuff. here I'd like to cite figure 1. I would also like a BibTex citation"}
ggplot(df, aes(cyl, hp)) + geom_point()
```
r latex r-markdown pandoc
r latex r-markdown pandoc
asked Nov 23 '18 at 1:00
Tony D
1118
1118
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
In my experience cross-referencing works better when one uses bookdown::pdf_document2
or bookdown::html_document2
. Note that it makes sense to name the chunk that produces the figure since that name is used in the label used for referencing:
---
title: "Untitled"
author: "me"
date: "today"
output:
bookdown::pdf_document2:
latex_engine: lualatex
number_sections: no
bookdown::html_document2:
default
linestretch: 1.5
bibliography: packages.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
knitr::write_bib(c(.packages()), 'packages.bib')
```
```{r}
df <- mtcars
library(ggplot2)
```
```{r stuff, fig.cap="some stuff"}
ggplot(df, aes(cyl, mpg)) + geom_point()
```
```{r, fig.cap="some more stuff. here I'd like to cite figure \@ref(fig:stuff). I would also like a BibTex citation [@R-base]"}
ggplot(df, aes(cyl, hp)) + geom_point()
```
For the BibTeX reference I am using an automatically created one, but the adaption to your case should be obvious.
That doesn't generalize tohtml_output
. It would be nice to have a solution that does.
– Frank Harrell
Nov 24 '18 at 13:34
1
@FrankHarrell For HTML output you can usebookdown::html_document2
. See updated answer.
– Ralf Stubner
Nov 24 '18 at 22:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439541%2fcite-figure-in-other-figure-caption-in-markdown-to-pdf%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In my experience cross-referencing works better when one uses bookdown::pdf_document2
or bookdown::html_document2
. Note that it makes sense to name the chunk that produces the figure since that name is used in the label used for referencing:
---
title: "Untitled"
author: "me"
date: "today"
output:
bookdown::pdf_document2:
latex_engine: lualatex
number_sections: no
bookdown::html_document2:
default
linestretch: 1.5
bibliography: packages.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
knitr::write_bib(c(.packages()), 'packages.bib')
```
```{r}
df <- mtcars
library(ggplot2)
```
```{r stuff, fig.cap="some stuff"}
ggplot(df, aes(cyl, mpg)) + geom_point()
```
```{r, fig.cap="some more stuff. here I'd like to cite figure \@ref(fig:stuff). I would also like a BibTex citation [@R-base]"}
ggplot(df, aes(cyl, hp)) + geom_point()
```
For the BibTeX reference I am using an automatically created one, but the adaption to your case should be obvious.
That doesn't generalize tohtml_output
. It would be nice to have a solution that does.
– Frank Harrell
Nov 24 '18 at 13:34
1
@FrankHarrell For HTML output you can usebookdown::html_document2
. See updated answer.
– Ralf Stubner
Nov 24 '18 at 22:06
add a comment |
In my experience cross-referencing works better when one uses bookdown::pdf_document2
or bookdown::html_document2
. Note that it makes sense to name the chunk that produces the figure since that name is used in the label used for referencing:
---
title: "Untitled"
author: "me"
date: "today"
output:
bookdown::pdf_document2:
latex_engine: lualatex
number_sections: no
bookdown::html_document2:
default
linestretch: 1.5
bibliography: packages.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
knitr::write_bib(c(.packages()), 'packages.bib')
```
```{r}
df <- mtcars
library(ggplot2)
```
```{r stuff, fig.cap="some stuff"}
ggplot(df, aes(cyl, mpg)) + geom_point()
```
```{r, fig.cap="some more stuff. here I'd like to cite figure \@ref(fig:stuff). I would also like a BibTex citation [@R-base]"}
ggplot(df, aes(cyl, hp)) + geom_point()
```
For the BibTeX reference I am using an automatically created one, but the adaption to your case should be obvious.
That doesn't generalize tohtml_output
. It would be nice to have a solution that does.
– Frank Harrell
Nov 24 '18 at 13:34
1
@FrankHarrell For HTML output you can usebookdown::html_document2
. See updated answer.
– Ralf Stubner
Nov 24 '18 at 22:06
add a comment |
In my experience cross-referencing works better when one uses bookdown::pdf_document2
or bookdown::html_document2
. Note that it makes sense to name the chunk that produces the figure since that name is used in the label used for referencing:
---
title: "Untitled"
author: "me"
date: "today"
output:
bookdown::pdf_document2:
latex_engine: lualatex
number_sections: no
bookdown::html_document2:
default
linestretch: 1.5
bibliography: packages.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
knitr::write_bib(c(.packages()), 'packages.bib')
```
```{r}
df <- mtcars
library(ggplot2)
```
```{r stuff, fig.cap="some stuff"}
ggplot(df, aes(cyl, mpg)) + geom_point()
```
```{r, fig.cap="some more stuff. here I'd like to cite figure \@ref(fig:stuff). I would also like a BibTex citation [@R-base]"}
ggplot(df, aes(cyl, hp)) + geom_point()
```
For the BibTeX reference I am using an automatically created one, but the adaption to your case should be obvious.
In my experience cross-referencing works better when one uses bookdown::pdf_document2
or bookdown::html_document2
. Note that it makes sense to name the chunk that produces the figure since that name is used in the label used for referencing:
---
title: "Untitled"
author: "me"
date: "today"
output:
bookdown::pdf_document2:
latex_engine: lualatex
number_sections: no
bookdown::html_document2:
default
linestretch: 1.5
bibliography: packages.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
knitr::write_bib(c(.packages()), 'packages.bib')
```
```{r}
df <- mtcars
library(ggplot2)
```
```{r stuff, fig.cap="some stuff"}
ggplot(df, aes(cyl, mpg)) + geom_point()
```
```{r, fig.cap="some more stuff. here I'd like to cite figure \@ref(fig:stuff). I would also like a BibTex citation [@R-base]"}
ggplot(df, aes(cyl, hp)) + geom_point()
```
For the BibTeX reference I am using an automatically created one, but the adaption to your case should be obvious.
edited Nov 24 '18 at 22:05
answered Nov 23 '18 at 7:36
Ralf Stubner
13.7k21437
13.7k21437
That doesn't generalize tohtml_output
. It would be nice to have a solution that does.
– Frank Harrell
Nov 24 '18 at 13:34
1
@FrankHarrell For HTML output you can usebookdown::html_document2
. See updated answer.
– Ralf Stubner
Nov 24 '18 at 22:06
add a comment |
That doesn't generalize tohtml_output
. It would be nice to have a solution that does.
– Frank Harrell
Nov 24 '18 at 13:34
1
@FrankHarrell For HTML output you can usebookdown::html_document2
. See updated answer.
– Ralf Stubner
Nov 24 '18 at 22:06
That doesn't generalize to
html_output
. It would be nice to have a solution that does.– Frank Harrell
Nov 24 '18 at 13:34
That doesn't generalize to
html_output
. It would be nice to have a solution that does.– Frank Harrell
Nov 24 '18 at 13:34
1
1
@FrankHarrell For HTML output you can use
bookdown::html_document2
. See updated answer.– Ralf Stubner
Nov 24 '18 at 22:06
@FrankHarrell For HTML output you can use
bookdown::html_document2
. See updated answer.– Ralf Stubner
Nov 24 '18 at 22:06
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439541%2fcite-figure-in-other-figure-caption-in-markdown-to-pdf%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown