0

I'm working on creating .docx documents using officer package. I've got a problem with body_add_toc() function, which creates and empty "table of content" (just a gray rectangle with no actual content). Even the example from the officer vignette doesn't seems to work for me. (I've simplified it a bit)

doc <- read_docx() %>% 
  body_add_par(value = "Table of content", style = "heading 1") %>% 
  body_add_toc(level = 2) %>% 

  body_add_par(value = "Tables", style = "heading 1")

print(doc, target = "toc.docx")

I've already tried to specify the body_add_toc() style argument as "heading" or "heading 1". I've also tried to change the body_add_par() and body_add_toc() style into "toc 1", but none of this solutons have helped me.

I'm working on Ubuntu 16.04, using R 3.4.3, officer 0.2.2 and magrittr 1.5

Thanks in advance for your help! Regards

Iga N
  • 1

1 Answers1

0

I had the same problem with Word 2016. The problem is caused by the Officer table of contents not being updated when you open the document in Word. Open the document in Word, then in the ribbon click on

References > Update Table

Then the table of contents should appear.

user2750268
  • 23
  • 1
  • 4