docx_plus.publishing.captions¶
Figure / table captions: a literal label run ("Figure ",
"Table ", etc.) followed by a SEQ complex field that
auto-numbers items sharing the same caption type. The caption type
is the same name a downstream Table of Figures uses to find
captions (see
docx_plus.publishing.figures).
Architecture walkthrough: ARCHITECTURE.md §7.10.
docx_plus.publishing.captions ¶
Figure / table captions — leading text + SEQ complex field.
A Word caption is a paragraph that opens with a label run (e.g.
"Figure ") followed by a SEQ complex field that auto-numbers
items of the same caption type. The Table of Figures (see
docx_plus.publishing.figures) picks up captions whose SEQ name
matches its \c switch.
This module imports only from docx_plus.core (SPEC §9.1).
add_caption ¶
add_caption(
paragraph: Paragraph,
label: str | None = None,
*,
caption_type: str = "Figure",
numbering: str = "ARABIC",
) -> etree._Element
Append a caption (label run + auto-numbered SEQ field).
The label is emitted as a literal text run; the number is a
SEQ complex field that Word re-numbers on open. After all
captions are inserted, call
:func:docx_plus.fields.mark_fields_dirty so Word recalculates
the SEQ values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paragraph
|
Paragraph
|
A python-docx :class: |
required |
label
|
str | None
|
Leading text shown before the number, including any
trailing whitespace. When omitted ( |
None
|
caption_type
|
str
|
The |
'Figure'
|
numbering
|
str
|
Word numbering format token for the |
'ARABIC'
|
Returns:
| Type | Description |
|---|---|
_Element
|
The |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Note
The caption's paragraph is not automatically restyled to
Word's built-in Caption paragraph style. Apply it yourself
if you want the conventional italic-grey rendering:
paragraph.style = doc.styles["Caption"].
Example
from docx import Document from docx_plus.publishing import add_caption doc = Document() p = doc.add_paragraph() add_caption(p, caption_type="Figure") # label defaults to "Figure " p.add_run(": Architecture overview")