w:fitText (Fit Text to Exact Width)

Stretches or compresses the characters of a run to exactly fill a specified width.

Parent elements

Description

w:fitText forces all characters in the run to occupy exactly the width specified by w:val, regardless of their natural width. The processor scales the spacing between and/or within characters to achieve the target width.

It is defined in ECMA-376 Part 1 §17.3.2.14.

This is commonly used in templates for fixed-width label fields where text must align across multiple items.

Attributes

Attribute Type Possible Values Description
w:val ST_TwipsMeasure Non-negative integer in twips (e.g. 1440 = 1 inch) Target width for the run’s characters.
w:id xsd:integer Positive integer, unique within the document Groups multiple w:fitText runs that should be scaled together.

Examples

<!-- Force run to exactly 1 inch wide -->
<w:r>
  <w:rPr>
    <w:fitText w:val="1440" w:id="1"/>
  </w:rPr>
  <w:t>Name</w:t>
</w:r>

Notes

  • 1 inch = 1440 twips, 1 cm ≈ 567 twips.
  • Runs that share the same w:id value are scaled together as a group — the same scale factor applies to all.
  • w:fitText overrides w:w (character scaling) when both are present.