Files
docx/docs/usage/tabs.md
T
DolanandClaude Opus 5.5 e0ff13ee3d chore: organise the demos into a folder for each topic (#3552)
* chore: organise the demos into a folder for each topic

The demos were one flat list of 124 numbered files, which made it hard to
find the one you wanted. Each is now in a folder for its topic, such as
demo/tables/basic-table.ts, with a name that says what it shows instead of
a number.

npm run demo lists every demo and narrows the list as you type. It also
takes a demo's path or name, a topic, or search words.

The demos' images moved to demo/assets/images, as images is now a topic.
The docs' links, the Demos workflow, the shape render script and its
reference images use the new paths and names.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ

* fix: list only a topic's own demos, and drop stale output file names

npm run demo text also offered the text-boxes demos and others with
"text" in their name, so a topic now searches for "text/". Three demos
logged their old numbered file name after writing My Document.docx.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 01:40:45 +01:00

5.7 KiB

Tabs and Tab Stops

Tab Stops

Tab stops are useful, if you are unclear of what they are, here is a link explaining. It enables side by side text which is nicely laid out without the need for tables, or constantly pressing space bar.

!> Note: The unit of measurement for a tab stop is in DXA

Word 2013 Tabs

Simply declare the tab stops on the paragraph, as shown below. Use the tab character \t or add the new Tab() child to indicate the tab position within the text property of a TextRun. Adding multiple tabStops will mean you can add additional \t characters until the desired tabStop is selected. Example is shown below.

Example

const paragraph = new Paragraph({
    children: [
        new TextRun({ text: "Hey everyone", bold: true }),
        new TextRun("\t11th November 1999"),
        new TextRun({
            children: [new Tab(), "11th November 1999"],
        }),
    ],
    tabStops: [
        {
            type: TabStopType.RIGHT,
            position: TabStopPosition.MAX,
        },
    ],
});

The example above will create a left aligned text, and a right aligned text on the same line. The laymans approach to this problem would be to either use text boxes or tables. Not ideal!

const paragraph = new Paragraph({
    children: [new TextRun("\t\tSecond tab stop here I come!")],
    tabStops: [
        {
            type: TabStopType.RIGHT,
            position: TabStopPosition.MAX,
        },
        {
            type: TabStopType.LEFT,
            position: 1000,
        },
    ],
});

The above shows the use of two tab stops, and how to select/use it.

You can add multiple tab stops of the same type too.

const paragraph = new Paragraph({
    children: [new TextRun("Multiple \ttab \tstops!")],
    tabStops: [
        {
            type: TabStopType.RIGHT,
            position: TabStopPosition.MAX,
        },
        {
            type: TabStopType.RIGHT,
            position: 1000,
        },
    ],
});

const paragraph = new Paragraph({
    children: [
        new TextRun({
            children: ["Multiple ", new Tab(), "tab ", new Tab(), "stops!"],
        }),
    ],
    tabStops: [
        {
            type: TabStopType.RIGHT,
            position: TabStopPosition.MAX,
        },
        {
            type: TabStopType.RIGHT,
            position: 1000,
        },
    ],
});

Left Tab Stop

const paragraph = new Paragraph({
    tabStops: [
        {
            type: TabStopType.LEFT,
            position: 2268,
        },
    ],
});

2268 is the distance from the left side.

Center Tab Stop

const paragraph = new Paragraph({
    tabStops: [
        {
            type: TabStopType.CENTER,
            position: 2268,
        },
    ],
});

2268 is the distance from the center.

Right Tab Stop

const paragraph = new Paragraph({
    tabStops: [
        {
            type: TabStopType.RIGHT,
            position: 2268,
        },
    ],
});

2268 is the distance from the left side.

Max Right Tab Stop

const paragraph = new Paragraph({
    tabStops: [
        {
            type: TabStopType.RIGHT,
            position: TabStopPosition.MAX,
        },
    ],
});

This will create a tab stop on the very edge of the right hand side. Handy for right aligning and left aligning text on the same line.

Positional Tabs

Positional tab allow you to create a tab stop that is relative to the margin, or the page. This is useful if you want to create a table of contents, or a table of figures.

They are easier to use than the normal tab stops, as you can use the PositionalTab class to create a tab stop, and then add the text to the TextRun children. Useful for most cases.

Word Positional Tabs

Example

new Paragraph({
    children: [
        new TextRun("Full name"),
        new TextRun({
            children: [
                new PositionalTab({
                    alignment: PositionalTabAlignment.RIGHT,
                    relativeTo: PositionalTabRelativeTo.MARGIN,
                    leader: PositionalTabLeader.DOT,
                }),
                "John Doe",
            ],
            bold: true,
        }),
    ],
}),

Options

Option Type Description Possible Values
alignment PositionalTabAlignment The alignment of the tab stop LEFT, RIGHT, CENTER
relativeTo PositionalTabRelativeTo The relative position of the tab stop MARGIN, INDENT
leader PositionalTabLeader The leader of the tab stop NONE, DOT, HYPHEN, UNDERSCORE, MIDDLE_DOT, EQUALS

Demos

Tab Stops Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/paragraphs/tab-stops.ts

Positional Tabs Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/paragraphs/positional-tabs.ts