1

I would like to have my tables display with a caption that shows chapter number and table number. A SO post says bookdown does not currently support that option. So I tried to add the caption directly into my flextable with a line like set_caption(caption = "Table 8.6"). When the page renders it includes both an automatic table number caption and my custom caption.

Table 8.6

I see how to disable the automatic captions in a pdf here but not how to remove them from HTML. How can I stop bookdown from assigning the automatic table captions?

Alternatively, has anybody found a way to add chapter numbers to the automatic captions?

My YAML header is here:

--- 
title: "Intro to Categorical Data Analysis 3rd Edition Notes"
author: "me"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
output:
  bookdown::gitbook: 
    config: 
      toc:
        collapse: false
    number_sections: false
    css: "style.css"
description: "Notes for Agresti's Introduction to Categorical Data Analysis"
---
itsMeInMiami
  • 2,324
  • 1
  • 13
  • 34
  • If you were to render to pdf, this is possible because you can define custom labels for tables. See here for a start: https://stackoverflow.com/questions/47173279/internationalization-r-knitr-figure-caption-label/47237025#47237025 . Adding - \renewcommand{\tablename}{Table \arabic{section}.} will include the section name in the label. – fry Feb 23 '22 at 14:50

1 Answers1

1

An ugly way to do it is to just add text ahead of the table, formatted to look like a caption. For example:

```{r echo=FALSE}
htmltools::p("Table 8.6: This is a new caption.", style="text-align:center")
flextable::flextable(head(mtcars))
```

This won't end up in the list of tables (if you have one), and you need to manually link to it from the text, e.g.

```{r echo=FALSE}
htmltools::a(name="newtab")
htmltools::p("Table 8.6: This is a new caption.", style="text-align:center")
flextable::flextable(head(mtcars))
```

That was Table <a href="#newtab">8.6</a>.
user2554330
  • 37,248
  • 4
  • 43
  • 90