Git Product home page Git Product logo

Comments (3)

davidgohel avatar davidgohel commented on September 21, 2024 1

It may be possible to build a TOC with 2 different styles (if it is, I will try to add the feature).

For now, if you want that kind of sequence, you need to go deeper in Word SEQ field. This makes things harder to write but still it is possible. I don't recommend this solution as it is not a standard and it makes the code more difficult to maintain.

# file index.Rmd

---
title: "officedown Example"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
biblio-style: apalike
link-citations: yes
description: "This is a minimal example of using the officedown package to write a Word document."
---



```{r include=FALSE}
library(knitr)
library(officedown)
library(officer)
library(magrittr)
opts_chunk$set(echo = TRUE)
any_zz <- list(
  run_word_field("STYLEREF 1 \\s"),
  ftext("."),
  run_autonum(seq_id = "fig", pre_label = "", post_label = "")
)
one_zz <- list(
  run_word_field("STYLEREF 1 \\s"),
  ftext("."),
  run_autonum(seq_id = "fig", start_at = 1, pre_label = "", post_label = "")
)
```


```{r}
block_toc(level = 1)
```


```{r}
block_toc(style = "Image Caption")
```


# file 01-intro.Rmd

# Introduction {#intro}


```{r}
plot(iris[, 4:5])
```

::: {custom-style="Image Caption"}
图 `r run_bookmark("iris", any_zz)` plot of iris
:::

Reference of \@ref(fig:iris)



```{r}
plot(iris[, 1:2])
```

::: {custom-style="Image Caption"}
图 `r run_bookmark("iris2", any_zz)` plot of iris2
:::

Reference of \@ref(fig:iris2)

# file 02-plots.Rmd

# Chapter 2 {#c2}


```{r}
plot(iris[, 2:3])
```

::: {custom-style="Image Caption"}
图 `r run_bookmark("iris3", one_zz)` plot of iris3
:::

Reference of \@ref(fig:iris3)

It produces this:

Capture d’écran 2021-02-17 à 16 31 17

Capture d’écran 2021-02-17 à 16 31 26

The idea is to reproduce Word functionality (:/ difficult to maintain) Restart numbering. That is represented by the instruction \\r 1. The sequence identifier is fig.

from officedown.

bishun945 avatar bishun945 commented on September 21, 2024

Thanks for your reply. It works!

Unfortunatley, I know little about Word SEQ field. But now I get that \\r 1 means restart to number from 1. Thus, for each chapter, what I need is to run_bookmark for the first figure based on one_zz and run other bookmarks based on any_zz. And the TOC could finally be generated by block_toc(seq_id = "fig").

By this way, the stuff about different styles seems unnecessary. But I am also happy to see that new feature.

from officedown.

davidgohel avatar davidgohel commented on September 21, 2024

I added an argument start_at in function run_autonum (and update the example below)

from officedown.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.