Apologies if this is already answered somewhere, but I am generating a report, and I want the table numbering to start at 2 rather than 1.
My r file looks like
#' ---
#' title: "Report"
#' author: "Me"
#' date: "June, 2025"
#'
#' ---
library(knitr)
kable(head(cars),caption='cars table') # This should be table 2
kable(head(iris),caption='iris table') # This should be table 3
and I'm generating the report with
rmarkdown::render("E:/test/test_table.R", output_file = "E:/test/test_table.pdf")
How can I set the number of the first table?
Any help appreciated.
Michael
What kind of document (HTML, PDF, Word) are you producing?
I do not use RMarkdown but in Quarto, producing aPDF file you can reset the table number to "2" with the command
\setcounter{table}{1}
vedoa
3
Hi @firbankm ,
thanks to @jrkrideau this should work for rmarkdown
---
title: 'Posit 203814'
output: pdf_document
date: "2025-06-20"
header-includes:
- \setcounter{table}{1}
---
```{r setup, include=FALSE}
library(knitr)
knitr::opts_chunk$set(echo = TRUE)
```
## Start at 2
```{r}
kable(head(cars), caption = 'cars table') # This will be Table 2
kable(head(iris), caption = 'iris table') # This will be Table 3
```
Output:
1 Like
Ah yes. I was just sticking the command in the body of the document. Putting it in the YAML is much tidier.