R Markdown 中主文本表的补充表链接

问题描述 投票:0回答:1

我一直在使用以下 LaTeX 命令在我的 R Markdown 文档中创建补充表:

\newcommand{\beginsupplement}{\setcounter{table}{0}  \renewcommand{\thetable}{S\arabic{table}} \setcounter{figure}{0} \renewcommand{\thefigure}{S\arabic{figure}}}

然而,最近这种联系被打破了。例如,当点击文本中的“Table S1”时,我将转到表 1。请参阅下面的示例:

---
title: 'Test Rmd document'
output:
  pdf_document
header-includes: 
- \newcommand{\beginsupplement}{\setcounter{table}{0}  \renewcommand{\thetable}{S\arabic{table}} \setcounter{figure}{0} \renewcommand{\thefigure}{S\arabic{figure}}}
---

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

library(kableExtra)
library(tibble)
```

## Main body
This is a main text table (\autoref{main_table}). There is also a supplementary table (\autoref{supplementary_table}).

```{r}
table <- tibble(a = 1:3, b = 4:6)
kable(table, 
      caption = "Main body table \\label{main_table}",
        format = "markdown")
```

\newpage
# Supplementary materials
\beginsupplement

```{r}
table <- tibble(a = 7:9, b = 10:12)
kable(table, 
      caption = "Supplementary table \\label{supplementary_table}",
        format = "markdown")
```

渲染上面的内容给出this pdf文档。为什么“(Table S1)”链接到表 1?

r latex r-markdown
1个回答
0
投票

技巧是为

\renewcommand
\thetable
添加
\theHtable
:

header-includes: 
- \newcommand{\beginsupplement}{\setcounter{table}{0}  \renewcommand{\thetable}{S\arabic{table}} \renewcommand{\theHtable}{S\arabic{table}} \setcounter{figure}{0} \renewcommand{\thefigure}{S\arabic{figure}} \renewcommand{\theHfigure}{S\arabic{figure}}}

同样适用于

\thefigure
/
\theHfigure

(参见这个答案

© www.soinside.com 2019 - 2024. All rights reserved.