Paragraphs

Tab stops

A Tab in a Run advances to the next TabStop of its paragraph. Each stop has a position, a TabAlignment that decides how the text sits relative to it, and a TabLeader that fills the space the tab jumps:

import WriteDocx as W

stops = [
    W.TabStop(6 * W.cm, alignment = W.TabAlignment.stop, leader = W.TabLeader.dot),
    W.TabStop(12 * W.cm, alignment = W.TabAlignment.decimal),
]

function row(label, amount)
    W.Paragraph(
        [W.Run([W.Text(label), W.Tab(), W.Text(""), W.Tab(), W.Text(amount)])],
        W.ParagraphProperties(tabs = stops),
    )
end

doc = W.Document(W.Body([W.Section([
    row("Coffee", "3.50"),
    row("Sandwich", "12.75"),
])]))

W.save("tab_stops.docx", doc)

Download tab_stops.docx:

Line spacing

The line of a Spacing sets how tall the lines of a paragraph are. A Percent is a multiple of single spacing, a Length fixes the height exactly, and an AtLeast lets Word grow the line to fit content taller than the given height:

import WriteDocx as W

function paragraph(line)
    W.Paragraph(
        [W.Run([W.Text("The quick brown fox jumps over the lazy dog. "^3)])],
        W.ParagraphProperties(spacing = W.Spacing(line = line)),
    )
end

doc = W.Document(W.Body([W.Section([
    paragraph(150 * W.percent),
    paragraph(14 * W.pt),
    paragraph(W.AtLeast(20 * W.pt)),
])]))

W.save("line_spacing.docx", doc)

Download line_spacing.docx: