如何在RMarkdown PDF文档中为附录表格添加A-前缀编号
解决方案:RMarkdown PDF中附录表格编号添加“A-”前缀
要实现正文表格正常编号、附录表格编号带“A-”前缀的效果,核心是借助LaTeX的计数器重置与格式重定义功能,修改后的完整代码如下:
--- title: "This is my title" date: "`r Sys.setlocale(locale = 'English') ; format(Sys.time(), '%B %d, %Y')`" output: pdf_document ---
library(tidyverse) library(knitr)
Results
tribble(~column1, ~column2, "value1", 2, "value2", 5 )%>% kable(booktabs=T, caption = "This is the caption of the first table")
\setcounter{table}{0}
\renewcommand{\thetable}{A-\arabic{table}}
Appendix
tribble(~column1, ~column2, "value1", 6, "value2", 8 )%>% kable(booktabs=T, caption = "This is the caption of the second table")
代码说明
\setcounter{table}{0}:将表格计数器重置为0,让附录表格从1开始计数\renewcommand{\thetable}{A-\arabic{table}}:重新定义表格编号格式,在阿拉伯数字前添加“A-”前缀
生成的PDF中,正文表格会显示为Table 1,附录表格会显示为Table A-1,完全符合需求。
内容的提问来源于stack exchange,提问作者TobKel
相关产品推荐
相关产品推荐

