问题描述
为什么 \ @ ref()
表示法不能与Beamer-presentation一起使用?
以下问题可能会在编织PDF文档时提醒您一些有关交叉引用的问题,例如
我的环境
- R版本3.5.1(2018-07-02)
- 平台:x86_64-w64-mingw32/x64(64位)
- 在以下操作系统上运行:Windows 10 x64(内部版本17134)
- knitr_1.20
- rmarkdown_1.10
- RStudio v1.2.1206 (预览版)<-我更喜欢此原因
MWE
我在此处发布的MWE是通过以下来源创建的: test-beamer.Rmd
和 myref.bib
.
test-beamer.Rmd
---标题:测试"字幕:||字幕,|换行作者:||CLR|拉斐尔研究所:|我现在就在这,|现在我在那里date:`r format(Sys.time(),'%Y/%b/%d')`"#英语输出:beamer_presentation:keep_tex:是的latex_engine:lualatex主题:"AnnArbor"colortheme:海豚"fonttheme:"structurebold"toc:正确#toc_depth:3#number_sections:正确fig_caption:正确开发:cairo_pdf#extra_dependencies:子图citation_package:natbibslide_level:2参考书目:bibs/myref.bib书目风格:apaalways_allow_html:是---```{r setup,include = FALSE}knitr :: opts_chunk $ set(echo = FALSE)```## 唯一的事情使用表\ @ref(tab:under-pressure-table),@ test-master显示图\ @ref(fig:under-pressure)表示...##我想在其中引用数字的带有项目符号的幻灯片-\ @ref(图:欠压)-@测试大师-\ @ref(tab:under-pressure-table)##滑动带R输出```{r汽车,echo = TRUE}摘要(汽车)```##带图滑动```{r压力不足,fig.cap ='压力不足',fig.pos ='h',out.width ="0.75 \\ textwidth"}情节(压力)```##滑台```{r under-pressure-table,caption ="This is a table"}针织物::电缆(压力)```##更非凡使用表\ @ref(tab:under-pressure-table),@ test-master显示图\ @ref(fig:under-pressure)表示...
我在图块上添加了 fig.cap ='Under Pressure',fig.pos ='h',out.width ="0.75 \\ textwidth"
和caption =这是一个表"
到 knitr :: kable()
.没有这些代码,标题和表格/数字都根本不会出现...但是,即使将它们提供给整个 .Rmd
文件,问题仍然存在,除非您执行@Yihui的回答.
myref.bib
@master {test-master,作者= {弗雷迪·水星(Freddie Mercury)和布莱恩·梅(Brian May)和约翰·迪肯(John Deacon)和罗杰·泰勒(Roger Taylor)},title = {波西米亚风{R} hapsody:{W} e是冠军},学校= {{Queen}},年= {2018},地址= {伦敦}}
\ @ ref()
表示法仅是 bookdown 的功能.要将此功能移植到一般的R Markdown文档中,您可以设置某种 bookdown 输出格式(例如
base_format
选项 输出:bookdown :: pdf_book:base_format:rmarkdown :: beamer_presentation
请参见 bookdown 图书的第3.4节第了解详情.
适合该问题的MWE的已完成yaml部分可能是这样的:
---标题:测试"字幕:||字幕,|换行作者:||CLR|拉斐尔研究所:|我现在就在这,|现在我在那里date:`r format(Sys.time(),'%Y/%b/%d')`"#英语输出:bookdown :: pdf_book:base_format:函数(...,number_sections)rmarkdown :: beamer_presentation(...)"number_sections:正确keep_tex:是的latex_engine:lualatex主题:"AnnArbor"colortheme:海豚"fonttheme:"structurebold"toc:正确fig_caption:正确开发:cairo_pdf#extra_dependencies:子图citation_package:natbibslide_level:2参考书目:bibs/myref.bib书目风格:apaalways_allow_html:是---
Why does \@ref()
notation fail to operate with beamer-presentation?
The following question may remind you some questions on cross-reference when knitting PDF document, e.g. this, but the methods introduced in the answers have not help me when I make beamer-presentations.
Now I'm confused because \@ref(fig:label-to-refer-figure)
and \@ref(tab:label-to-refer-table)
notation to refer a figure/table does not work when I am knitting an .Rmd
file with the option output: beamer_presentation
. As shown in the following images, the raw codes for the cross-reference appear on the outputted PDF file and I cannot refer the figure/table number. Although the citations go well even in the listed environment as well as in plain text field, cross-reference for figure/table number does not properly take effect.
My environment
- R version 3.5.1 (2018-07-02)
- Platform: x86_64-w64-mingw32/x64 (64-bit)
- Running under: Windows 10 x64 (build 17134)
- knitr_1.20
- rmarkdown_1.10
- RStudio v1.2.1206 (Preview Version) <- I prefer this for this reason
MWEs
The MWE I post here is created from the following sources: test-beamer.Rmd
and myref.bib
.
test-beamer.Rmd
---
title: "Test"
subtitle: |
| subtitle,
| with a line break
author: |
| CLR
| Rafael
institute: |
| Now I'm here,
| Now I'm there
date: "`r format(Sys.time(), '%Y/%b/%d')`" #English
output:
beamer_presentation:
keep_tex: yes
latex_engine: lualatex
theme: "AnnArbor"
colortheme: "dolphin"
fonttheme: "structurebold"
toc: true
#toc_depth: 3
#number_sections: TRUE
fig_caption: TRUE
dev: cairo_pdf
#extra_dependencies: subfig
citation_package: natbib
slide_level: 2
bibliography: bibs/myref.bib
biblio-style: apa
always_allow_html: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## The only thing
With Table \@ref(tab:under-pressure-table), @test-master shows that Figure \@ref(fig:under-pressure) depicts...
## Slide with Bullets in which I want to refer a figure
- \@ref(fig:under-pressure)
- @test-master
- \@ref(tab:under-pressure-table)
## Slide with R Output
```{r cars, echo = TRUE}
summary(cars)
```
## Slide with Plot
```{r under-pressure, fig.cap='Under Pressure', fig.pos='h', out.width="0.75\\textwidth"}
plot(pressure)
```
## Slide with Table
```{r under-pressure-table, caption = "This is a table"}
knitr::kable(pressure)
```
## More extraordinary
With Table \@ref(tab:under-pressure-table), @test-master shows that Figure \@ref(fig:under-pressure) depicts...
EDIT: I added fig.cap='Under Pressure', fig.pos='h', out.width="0.75\\textwidth"
to the figure chunk, and caption = "This is a table"
to the knitr::kable()
. Without these codes, neither the caption nor table/figure numbers appear at all... However, the problem persists even after giving them to the entire .Rmd
file, unless you carry out @Yihui's answer.
myref.bib
@master{test-master,
author = {Freddie Mercury and Brian May and John Deacon and Roger Taylor},
title = {Bohemian {R}hapsody: {W}e are the champions},
school = {{Queen}},
year = {2018},
address = {London}
}
The \@ref()
notation is a feature of bookdown only. To port this feature to general R Markdown documents, you may set the base_format
option of a certain bookdown output format, e.g.,
output:
bookdown::pdf_book:
base_format: rmarkdown::beamer_presentation
See Section 3.4 of the bookdown book for details.
The completed yaml section which suits for the MWE of this question may be like this:
---
title: "Test"
subtitle: |
| subtitle,
| with a line break
author: |
| CLR
| Rafael
institute: |
| Now I'm here,
| Now I'm there
date: "`r format(Sys.time(), '%Y/%b/%d')`" #English
output:
bookdown::pdf_book:
base_format: "function(..., number_sections) rmarkdown::beamer_presentation(...)"
number_sections: true
keep_tex: yes
latex_engine: lualatex
theme: "AnnArbor"
colortheme: "dolphin"
fonttheme: "structurebold"
toc: true
fig_caption: TRUE
dev: cairo_pdf
#extra_dependencies: subfig
citation_package: natbib
slide_level: 2
bibliography: bibs/myref.bib
biblio-style: apa
always_allow_html: yes
---
这篇关于无法在knitr中使用"beamer_presentation"选项交叉引用图和表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!