officer icon indicating copy to clipboard operation
officer copied to clipboard

Name for `tab.id` must not contain `_`?

Open SchmidtPaul opened this issue 1 year ago • 0 comments

Hi, fantastic package!

  1. I think that I cannot use an _ inside a name for a tab.id when using cross-references. I created a reprex below. I would simply ignore this, but you specifically suggest using one here in the officeverse book?
  2. Also in the same reprex: Why are Table 1 and 3 written in bold, but Table 2 and 4 are not?

Thanks!

---
output: officedown::rdocx_document
---
  
```{r setup, include=FALSE}
library(officedown)
library(officer)
```

# No underscore in `tab.id`

## Cross-references

```{r tab.cap="head of mtcars table", tab.id = "mtcarshead", tab.cap.style = "Table Caption", echo = FALSE}
head(mtcars, 3)
```

I can reference \@ref(tab:mtcarshead) the normal way.

```{r, results='asis', echo=FALSE}
cat(paste("I can reference \\@ref(tab:mtcarshead) via R-chunk (results='asis')"))
```

## Custom cross-references

```{r, echo = FALSE}
TabCrossRef <- function(tabref, TableLabel) {
  run_num <-
    run_autonum(
      seq_id = "tab",
      pre_label = "Table ",
      bkm = tabref
    )
  
  block_caption(label = TableLabel,
                style = "Table Caption",
                autonum = run_num)
}
```

```{r, echo = FALSE}
TabCrossRef("mtcarstail", "tail of mtcars table")
tail(mtcars, 3)
```

I can reference \@ref(tab:mtcarstail) the normal way.

```{r, results='asis', echo=FALSE}
cat(paste("I can reference \\@ref(tab:mtcarstail) via R-chunk (results='asis')"))
```
\newpage

# Underscore in `tab.id`

## Cross-references

```{r tab.cap="head of mtcars table", tab.id = "mtcars_head", tab.cap.style = "Table Caption", echo = FALSE}
head(mtcars, 3)
```

I can reference \@ref(tab:mtcars_head) the normal way.

```{r, results='asis', echo=FALSE}
cat(paste("I can reference \\@ref(tab:mtcars_head) via R-chunk (results='asis')"))
```

## Custom cross-references

```{r, echo = FALSE}
TabCrossRef <- function(tabref, TableLabel) {
  run_num <-
    run_autonum(
      seq_id = "tab",
      pre_label = "Table ",
      bkm = tabref
    )
  
  block_caption(label = TableLabel,
                style = "Table Caption",
                autonum = run_num)
}
```

```{r, echo = FALSE}
TabCrossRef("mtcars_tail", "tail of mtcars table")
tail(mtcars, 3)
```
I can reference \@ref(tab:mtcars_tail) the normal way.

```{r, results='asis', echo=FALSE}
cat(paste("I can reference \\@ref(tab:mtcars_tail) via R-chunk (results='asis')"))
```

image

SchmidtPaul avatar Jul 22 '22 13:07 SchmidtPaul