r标记图形标题打印不正确

r标记图形标题打印不正确,r,r-markdown,rstudio,R,R Markdown,Rstudio,我目前正在使用Rstudio并运行以下代码: {r top_3pt_scorers, echo = FALSE} top_3pt_shooters <- NBAdf %>% filter(PTS_TYPE == 3) %>% group_by(PLAYER_NAME) %>% dplyr::summarize(Threes_attempted = n(), Threes_made = sum(as.numeric(FGM)), Thr

我目前正在使用Rstudio并运行以下代码:

{r top_3pt_scorers, echo = FALSE}

top_3pt_shooters <- NBAdf %>%
  filter(PTS_TYPE == 3) %>%
  group_by(PLAYER_NAME) %>%
  dplyr::summarize(Threes_attempted = n(), Threes_made = sum(as.numeric(FGM)),
            Three_point_total = sum(PTS, na.rm = TRUE))

knitr::kable(head(top_3pt_shooters[order(top_3pt_shooters$Threes_made, decreasing = TRUE), ]),
             caption = "The top 3 point scorers in the NBA")


这似乎是一个代码块问题。试试这个:

```{r top_3pt_scorers, echo = FALSE}

top_3pt_shooters <- NBAdf %>%
  filter(PTS_TYPE == 3) %>%
  group_by(PLAYER_NAME) %>%
  dplyr::summarize(Threes_attempted = n(), Threes_made = sum(as.numeric(FGM)),
            Three_point_total = sum(PTS, na.rm = TRUE))

knitr::kable(head(top_3pt_shooters[order(top_3pt_shooters$Threes_made, decreasing = TRUE), ]),
             caption = "The top 3 point scorers in the NBA")
```
-输出


您要找的是哪一个数字标题?它正在打印代码块的名称。可能是您的
.Rmd
文件中的其他内容(例如YAML头)?可能您需要添加类似的内容?感谢您提供的链接,但我需要的是表格标题而不是数字,例如“表1:NBA前三名得分手”和下面的表它在另外两个表上运行正常,但其余的表都不工作我只是添加了屏幕截图来解释更好我只是尝试了你的解决方案,但对我来说没有成功,它只是输出相同的问题。你能提供一个最小的可重复的例子吗?如果不知道
.Rmd
文件的其他部分,就很难知道发生了什么。谢谢,我刚刚在帖子中添加了我使用的所有内容。我找到了解决方案!所以它不喜欢
{r top_3pt_scorers}
,我不得不将它改为
{r top 3ptscorers}
它似乎不喜欢下划线,我看到了,很高兴听到!您可以编辑我的答案或发布一个新的解释您的解决方案。
{r top3ptscorers, echo = FALSE}
```{r top_3pt_scorers, echo = FALSE}

top_3pt_shooters <- NBAdf %>%
  filter(PTS_TYPE == 3) %>%
  group_by(PLAYER_NAME) %>%
  dplyr::summarize(Threes_attempted = n(), Threes_made = sum(as.numeric(FGM)),
            Three_point_total = sum(PTS, na.rm = TRUE))

knitr::kable(head(top_3pt_shooters[order(top_3pt_shooters$Threes_made, decreasing = TRUE), ]),
             caption = "The top 3 point scorers in the NBA")
```
---
title: "Caption"
author: "bttomio"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: 
  pdf_document:
    fig_caption: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(kableExtra)
```

## Caption with kable

```{r dt}
dt <- mtcars[1:5, 1:6]
kbl(dt, caption = "Demo table", booktabs = T) %>%
  kable_styling(latex_options =c("striped", "hold_position"))
```

```{r dt2}
dt <- mtcars[1:5, 1:6]
kbl(dt, caption = "Same demo table", booktabs = T) %>%
  kable_styling(latex_options =c("striped", "hold_position"))
```