Last active
September 30, 2015 09:20
-
-
Save TomHarrop/3f46d760752954645c8d to your computer and use it in GitHub Desktop.
Use of \renewcommand and \protect to get custom figure caption prefixes and references in Tufte-handout PDF using knitr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
output: | |
rmarkdown::tufte_handout: | |
default | |
header-includes: | |
\usepackage{caption} | |
\captionsetup[figure]{labelfont=bf} | |
\renewcommand{\thefigure}{S\arabic{figure}} | |
--- | |
``` {r setup} | |
library(ggplot2) | |
data("mtcars") | |
knitr::opts_chunk$set( | |
out.width = 3.150, | |
out.height = 3.150 | |
) | |
``` | |
```{r myPlot, fig.cap = "\\protect\\label{fig:myPlot}My plot"} | |
g <- ggplot(mtcars, aes(x = cyl, y = mpg)) + geom_point() | |
print(g + theme_minimal(base_size = 8, base_family = "Helvetica")) | |
``` | |
Some text about \ref{fig:myPlot}. | |
```{r anotherPlot, fig.cap = "Another plot. Compare this to \\ref{fig:myPlot}"} | |
g <- ggplot(mtcars, aes(x = disp, y = mpg)) + geom_point() | |
print(g + theme_minimal(base_size = 8, base_family = "Helvetica")) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment