-
Notifications
You must be signed in to change notification settings - Fork 1.3k
A follow up on the issue of Figure caption #359
Description
Thanks to the latest developments presented in #137 it is now possible to insert an automatic figure or table caption using the following code.
def Figure(paragraph):
run = run = paragraph.add_run()
r = run._r
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'begin')
r.append(fldChar)
instrText = OxmlElement('w:instrText')
instrText.text = ' SEQ Figure * ARABIC'
r.append(instrText)
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'end')
r.append(fldChar)
def Table(paragraph):
run = run = paragraph.add_run()
r = run._r
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'begin')
r.append(fldChar)
instrText = OxmlElement('w:instrText')
instrText.text = ' SEQ Table * ARABIC'
r.append(instrText)
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'end')
r.append(fldChar)
-----------in the main document-------
paragraph = document.add_paragraph('Figure ', style='Caption')
Figure (paragraph)
--- while the figure or table number might not appear immediately they will show up after an update
moreover the code can be viewed using the "toggle field view"
Thanks to everybody